Author Topic: render function in pqGrid not behaving properly...  (Read 4026 times)

onyxplyr

  • Newbie
  • *
  • Posts: 10
    • View Profile
render function in pqGrid not behaving properly...
« on: August 08, 2016, 05:48:11 pm »
Good day, all:

I am trying to use the render function to display an imagebutton in a column given a value returned in each data row (much like the example given on the demo site with the up and down arrows).  I am evaluating whether a column's value equals one of two values; if the value is 1, then display the image button, if it's 0 (zero), display nothing.  The problem is that either all rows get an image button or none of them do, depending on how I write the condition.  Here is the code:

$(function () {
        var obj = {
            width: 580,
            height: 700,
            wrap: false,
            hwrap: false,
            editable: false,
            showTop: false,
            showBottom: false,
            collapsible: false,
            showHeader: true,
            resizable: true,
            columnBorders: true,
            rowBorders: true,
            flexHeight: true,
            virtualX: false,
            sortable: false,
            numberCell: { show: true },
            filterModel: { mode: "AND", header: true },
            scrollModel: { autoFit: true, pace: 'optimum' },
            selectionModel: { type: 'row', mode: 'single' },
            title: "Report Periods",
            colModel: [
                { title: "ReportPeriodId", dataType: "integer", dataIndx: "ReportPeriodId", hidden: true },
                { title: "Report Date", width: 75, dataType: "string", dataIndx: "ReportPeriodName" },
                { title: "Date Span", width: 75, dataType: "string", dataIndx: "ReportPeriodDtSpan" },
                { title: "Upload Available", dataType: "integer", dataIndx: "UploadAvailable" },
                {
                    title: "", editable: false, sortable: false, width: 100, align: "center", render: function (ui) {
                        var rowData = ui.rowData;
                        if (rowData[3] = 1) { 
                            return "<input type='image' src='../../images/1450567121_editor-pencil-pen-edit-write-glyph.ico' onClick=\"location.href='..." + rowData.ReportPeriodId + "';\" title='Edit Info' width='20' height='20'>";
                        }
                        else
                        {
                            return "";
                        }
                    }
                }
            ],
            dataModel: {
                dataType: "JSON",
                location: "remote",
                recIndx: "ReportPeriodId",
                url: "/Home/ReportPeriodsByAcademicYear",
                getData: function (dataJSON) {
                    return { data: dataJSON.data };
                }
            },
            pageModel: { type: 'local', rPP: 20 }
        }

        var grid = $("#grid_ReportPeriods").pqGrid(obj);
        //var colM = grid.pqGrid("option", "colModel");

        //grid.pqGrid("option", "colModel", colM);
        //grid.pqGrid('refreshDataAndView');
    });

I am following the demo exactly and I've used the developer tools in Chrome to debug.  I have viewed what is being returned for 'rowData' and I can see the value in the array I want to evaluate, but it doesn't work.

Please advise.

Sincere thanks!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: render function in pqGrid not behaving properly...
« Reply #1 on: August 08, 2016, 06:01:07 pm »
Row data is an array in the example but you have been using JSON data.

So rowData[3] = 1 needs correction:

1) use equality operator ( === ) instead of assignment ( = )

2) use dataIndx as string instead of numeric colIndx

if ( rowData['dataIndx_of_column'] == 1 )

onyxplyr

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: render function in pqGrid not behaving properly...
« Reply #2 on: August 08, 2016, 06:14:14 pm »
Many thanks!!!  That was exactly the issue.

This is one of the best tools I've ever used!  Powerful!

Have a good one!