Custom Template List Page for DB View

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
DGarza
User
Posts: 152

Custom Template List Page for DB View

Post by DGarza »

Hi everyone

I discovered that {{{dbvalue fielname}}} does not work properly when you call it from a view(DB view) list page CustomTemplateBody brings the information in the following way “root.rows[0].fildName”, I need to use {{{dbvalue fieldname}}}, because I need to use it in an if condition, but when bringing me the wrong information, it is not working.

NOTE: This only does NOT work well inside a view(db view) list page CustomTemplateBody, since in the main table, {{{dbvalue fieldname}}} does bring correctly the information.

*This only not works with Fields-> Use lookup Table (Foreign Key Field), I just tried on view(DB view) but not, its just for lookup table field

How can I use the If condition on Customtemplate on Lookup Table field?

Thank you


sangnandar
User
Posts: 1031

Post by sangnandar »

Check first at your db if the fieldname fetch the correct value

select * from yourView;

If it fetch the correct value, it should be accessible in phpm, either with normal page or custom-template.


DGarza
User
Posts: 152

Post by DGarza »

Thank you for response
I did the SELECT and work perfectly on my DB, the problem its in my CustomTemplate, when I tried to {{{dbvalue lookuptablefield}}} this is the answered “root.rows[0].lookuptablename”, so I can't use for my condition


sangnandar
User
Posts: 1031

Post by sangnandar »

Please read the documentation

Important Notes

  1. ALWAYS use JsRender template tags together with this tag, e.g. {{: {{{dbvalue field}}} }}, see more examples below.

If you want to output the value into page, do

Example 1 - Output the field value directly

{{: {{{dbvalue field}}} }}

If you want to run condition, do

Example 6 - Output field value with JsRender {{if ...}} and {{else ...}} tags.

{{if {{{dbvalue field}}} == "Y" }}Yes{{else {{{dbvalue field}}} == "N" }}No{{else}}Unknown{{/if}}

DGarza
User
Posts: 152

Post by DGarza »

sangnandar wrote:

If you want to output the value into page, do > Example 1 - Output the field value directly

{{: {{{dbvalue field}}} }}

If you want to run condition, do > Example 6 - Output field value with JsRender {{if ...}} and {{else ...}} tags.

{{if {{{dbvalue field}}} == "Y" }}Yes{{else {{{dbvalue field}}} ==  "N" }}No{{else}}Unknown{{/if}}

All of this doesn't work, I mean, the way to bring the the value of lookupfield its {{: {{{dbvalue lookupfield}}} }}, but when I use the IF, the example that give in the Documentation, DONT work, i have an error on console
and I tried with this

{{if: {{{dbvalue Status}}} == "Abierto" }}
        <td data-name="Status" class="bg-success">
            {{{value Status}}}
        </td>
        {{else: {{{dbvalue Status}}} == "Pausado" }}
        <td data-name="Status" class="bg-info">
            {{{value Status}}}
        </td>
{{/if}}

But this dont work too, if you can give with some example it works, I will be grateful.

Thank you for response


arbei
User
Posts: 9787

Post by arbei »

DGarza wrote:

{{if: {{{dbvalue Status}}} == "Abierto" }}
{{else: {{{dbvalue Status}}} == "Pausado" }}

You have wrong syntax, remove ":".


DGarza
User
Posts: 152

Post by DGarza »

If I remove ":" and let de syntax like {{if {{{dbvalue Status}}} == "Abierto" }} bring the value like this ~root.rows[0].lookuptablename and dont work.


DGarza
User
Posts: 152

Post by DGarza »

This is my view schema:

SELECT dbo.Ticket.ID, dbo.Ticket.Titulo, dbo.Tipo_Incidente.Nombre AS Tipo_Incidente, dbo.Departamento.Nombre AS Departamento, dbo.Ticket.Descripcion, dbo.Status.Nombre AS Status, dbo.Prioridad.Nombre AS Prioridad, dbo.Ticket.Imagen, 
                  dbo.Ticket.ImagenSize, dbo.Ticket.ImagenType, dbo.Ticket.Date_Created, dbo.Ticket.Date_Done, dbo.Ticket.FKAgente AS AgenteAsignado, dbo.Ticket.Descripcion_Agente, dbo.Ticket.FKUser AS UsuarioID, dbo.Users.Nombre, 
                  dbo.Users.FotoLogin
FROM     dbo.Ticket RIGHT OUTER JOIN
                  dbo.Users ON dbo.Ticket.FKUser = dbo.Users.ID INNER JOIN
                  dbo.Departamento ON dbo.Users.FKDepartamento = dbo.Departamento.ID INNER JOIN
                  dbo.Status ON dbo.Ticket.FKStatus = dbo.Status.ID INNER JOIN
                  dbo.Prioridad ON dbo.Ticket.FKPrioridad = dbo.Prioridad.ID INNER JOIN
                  dbo.Tipo_Incidente ON dbo.Ticket.FKIncidente = dbo.Tipo_Incidente.ID
WHERE  (dbo.Ticket.FKStatus = '1') OR
                  (dbo.Ticket.FKStatus = '2')

I change the way to bring the Field Status and dont use a lookup Table, but its the same when I use {{{dbvalue Status}}} the value its ~root.rows[0].Status and its the same thing with Field Departamento and Field Prioridad


DGarza
User
Posts: 152

Post by DGarza »

Nevermind {{{dbvalue field}}} doesn't work in a view (DB view), I tried {{{dbvalue field}}} on the main table and works properly

I change all the fileds value {{{value field}}} to {{{dbvalue field}}} and all the values were ~root.rows[0].field

I know if I use {{: {{{dbvalue field}}} }} works properly on the view(DB view), but how can I convine this {{: {{{dbvalue field}}} }} with the IF condition


sangnandar
User
Posts: 1031

Post by sangnandar »

It should work. I've been using Jsrender switch (condition) countless times in List/Add/Edit/Delete pages.
Always re-check your code. Jsrender syntax is tricky due to a lot of curly brackets.

However, looking at your code, if you just want to change the cell-class, that is <td class="...">, it would be simpler to do that server-side rather than client-side (Jsrender).

public function rowRendered()
{
  if ($this->PageID === 'list') {
    $this->(fieldname)->CellCssClass .= 'something';
  }
}

DGarza
User
Posts: 152

Post by DGarza »

sangnandar wrote:

It should work. I've been using Jsrender switch (condition) countless times in List/Add/Edit/Delete pages. Always re-check your code. Jsrender syntax is tricky due to a lot of curly brackets.

Trust me the way that bring me the values, its wrong, so, i can not do anything

However, looking at your code, if you just want to change the cell-class, that is <td class="...">, it would be simpler to do that server-side rather than client-side (Jsrender).

 public function rowRendered()
 {
   if ($this->PageID === 'list') {
     $this->(fieldname)->CellCssClass .= 'something';
   }
 }

I was using the next code before use the CustomTemplate

 public function rowRendered()
 {
   if ($this->PageID === 'list') {
     $this->(fieldname)->CellAttrs["class"] = "comething";
   }
 }

But now dont work, that the only reason that I want to use JDRende, I'm gonna try with your sintax


DGarza
User
Posts: 152

Post by DGarza »

I tried with your code but doen't work, this is my code

if ($this->Prioridad->CurrentValue == "Baja" && $this->PageID == "list") {
    		$this->Prioridad->CellCssClass .= 'bg-primary';
}

arbei
User
Posts: 9787

Post by arbei »

Note that when you use a view, the data type of the field might be changed to long text type which is by default not outputted for Custom Template, in your SQL of the view you may use Cast Functions to convert the value to VARCHAR(n).


DGarza
User
Posts: 152

Post by DGarza »

No men:( its the same: ~root.rows[0].Status (The way to bringe the value when put {{{dbvalue Status}}} )
This is my new schema view:

SELECT dbo.Ticket.ID, dbo.Ticket.Titulo, dbo.Tipo_Incidente.Nombre AS Tipo_Incidente, dbo.Departamento.Nombre AS Departamento, dbo.Ticket.Descripcion, CAST(dbo.Status.Nombre AS VARCHAR(25)) AS Status, dbo.Prioridad.Nombre AS Prioridad,
dbo.Ticket.Imagen, dbo.Ticket.ImagenSize, dbo.Ticket.ImagenType, dbo.Ticket.Date_Created, dbo.Ticket.Date_Done, dbo.Ticket.FKAgente AS AgenteAsignado, dbo.Ticket.Descripcion_Agente, dbo.Ticket.FKUser AS UsuarioID,
dbo.Users.Nombre, dbo.Users.FotoLogin
FROM dbo.Ticket RIGHT OUTER JOIN
dbo.Users ON dbo.Ticket.FKUser = dbo.Users.ID INNER JOIN
dbo.Departamento ON dbo.Users.FKDepartamento = dbo.Departamento.ID INNER JOIN
dbo.Status ON dbo.Ticket.FKStatus = dbo.Status.ID INNER JOIN
dbo.Prioridad ON dbo.Ticket.FKPrioridad = dbo.Prioridad.ID INNER JOIN
dbo.Tipo_Incidente ON dbo.Ticket.FKIncidente = dbo.Tipo_Incidente.ID
WHERE (dbo.Ticket.FKStatus = '1') OR
(dbo.Ticket.FKStatus = '2')


arbei
User
Posts: 9787

Post by arbei »

You may press F12 in your browser and go the Console panel, enter the follows to check the JSON for the custom template and see if your data outputted: ew.templateData.


Post Reply