Author Topic: Upgrading v2.4 to v3.2  (Read 4624 times)

lgauton

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 44
    • View Profile
Upgrading v2.4 to v3.2
« on: February 12, 2016, 09:18:23 pm »
Hi Having a problem moving from v2.4 to v3.2 - all code works correctly using v2.4 but after moving to v3.2 my grids are empty of data. I've checked the requirements and all js and css I think are need are loaded on the page. From chnagelog all I needed to do was change to sortModel, here's example code if any can spot where it's wrong please respond

                var colModelhl = [
                { title: "Code", dataType: "string", width: "50", dataIndx: 0, render: filterRender },
                { title: "Name", dataType: "string", width: "250", dataIndx: 1, render: filterRender },
                { title: "Resort Name", dataType: "string", width: "250", dataIndx: 4, render: filterRender },
                { title: "Country", dataType: "string", width: "100", dataIndx: 6, render: filterRender },
                { title: "InActive", dataType: "string", width: "100", dataIndx: 2 }
                ];

                var dataModelhl = {
                    //cache: true,
                    location: "remote",
                    dataType: "xml",
                    method: "POST",
                    getUrl: function () {
                        return {
                            url: "@Url.ModuleUrl().Action("AccessHotelList")",
                            data: { 'id': ctr }
                        };
                    },
                    getData: function (dataDoc) {
                        //debugger;
                        var obj = { itemParent: "BriefAccommodationInfo", itemNames: ["code", "name", "inactive", "resortCode", "resortName", "countryCode", "countryName"] };
                        return { data: $.paramquery.xmlToArray(dataDoc, obj) };
                    }
                };

                var sortModelhl = {
                    cancel: false,
                    single: true,
                    type: "local",
                    sorter: [{ dataIndx: "name", dir: "up" }]
                };

                var obj = {
                    width: 750, height: 0,
                    dataModel: dataModelhl,
                    colModel: colModelhl,
                    sortModel: sortModelhl,
                    pageModel: { rPP: 10, type: "local", rPPOptions: [1, 2, 5, 10, 20, 100] },
                    title: "<b>Hotel List</b>",
                    flexHeight: true,
                    paging: true,
                    draggable: false,
                    editable: false,
                    //resizable:true,           
                    scrollModel: { horizontal: false },
                    numberCell: false,
                    selectionModel: {
                        type: 'row', mode: 'single'
                    },
                    filterModel: { mode: 'OR', type: 'local' },
                    toolbar: {
                        cls: "pq-toolbar-search",
                        items: [
                            { type: "<span style='margin:5px;'>Filter</span>" },
                            { type: 'textbox', attr: 'placeholder="Enter your keyword"', cls: "filterValue", listeners: [{ 'keyup': filterhandler }] },
                            {
                                type: 'select', cls: "filterColumn",
                                listeners: [{ 'change': filterhandler }],
                                options: function (ui) {
                                    var CM = ui.colModel;
                                    var opts = [{ '': '[ All Fields ]' }];
                                    for (var i = 0; i < CM.length; i++) {
                                        var column = CM;
                                        var obj = {};
                                        obj[column.dataIndx] = column.title;
                                        opts.push(obj);
                                    }
                                    return opts;
                                }
                            },
                            {
                               type: 'select', style: "margin:0px 5px;", cls: "filterCondition",
                               listeners: [{ 'change': filterhandler }],
                               options: [
                               { "contain": "Contains" },
                               { "begin": "Begins With" },
                               { "end": "Ends With" },
                               { "notcontain": "Does not contain" },
                               { "equal": "Equal To" },
                               { "notequal": "Not Equal To" },
                               { "empty": "Empty" },
                               { "notempty": "Not Empty" },
                               { "less": "Less Than" },
                               { "great": "Great Than" },
                               { "regexp": "Regex" }
                               ]
                            },
                            {
                                type: 'button', icon: 'ui-icon-plus', label: 'Duplicate Property', listeners: [
                                  {
                                      "click": function (evt, ui) {

                                          //add empty item
                                          duplicateProperty(evt, ui);

                                      }
                                  }
                                ]
                            },
                            {
                                type: 'button', icon: 'ui-icon-plus', label: 'Refresh list', listeners: [
                                  {
                                      "click": function (evt, ui) {

                                          //add empty item
                                          refreshHotellist("1");

                                      }
                                  }
                                ]
                            }
                        ]
                    },
                    load: function(evt, ui){
                        var $grid = $(this),
                            data = $grid.pqGrid('option','dataModel.data');

                        $.each(data, function (i, rowData) {
                            if (rowData[2] == "true") {
                                //alert("r" + i.toString());
                                $grid.pqGrid("addClass", { rowIndx: i, cls: "pq-red" });
                               
                            }
                        });
                       
                    },
                    collapsible: { on: true, collapsed: false },
                    freezeCols: 0,
                    rowSelect: loadHotel
                };

                $gridhl = $("#HotelGrid").pqGrid(obj);

                $gridhl = $("#HotelGrid").pqGrid("refresh");

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #1 on: February 12, 2016, 10:22:39 pm »
The context of callbacks and events has changed, inside the load event reference to $grid can be obtained as

var $grid = this.widget()

instead of

var $grid = $(this)

http://paramquery.com/pro/upgrade
« Last Edit: February 12, 2016, 10:56:58 pm by paramquery »

lgauton

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #2 on: February 15, 2016, 06:36:25 pm »
Hi I Have made the change you suggest but this doesn't help - still empty grid

                    load: function(evt, ui){
                        var $grid = this.widget(),
                            data = $grid.pqGrid('option','dataModel.data');

                        $.each(data, function (i, rowData) {
                            if (rowData[2] == "true") {
                                //alert("r" + i.toString());
                                $grid.pqGrid("addClass", { rowIndx: i, cls: "pq-red" });
                               
                            }
                        });
                       
                    },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #3 on: February 15, 2016, 06:44:21 pm »
dataIndx in the sortModel.sorter in your code doesn't match with any dataIndx in the colModel.

Code: [Select]
sorter: [{ dataIndx: "name", dir: "up" }]

Please correct it and check the browser console for any errors.
« Last Edit: February 15, 2016, 06:47:09 pm by paramquery »

lgauton

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #4 on: February 15, 2016, 07:54:43 pm »
Hi Thanks for the suggestion but thats not the issue stopping data records displaying. I have stripped out the sort conditions and other rendering and filtering - but still not data records are display. I can see then in the getData section by tracking dataDoc results - adjusted code below

                var colModelhl = [
                { title: "Code", dataType: "string", width: "50", dataIndx: 0},
                { title: "Name", dataType: "string", width: "250", dataIndx: 1 },
                { title: "Resort Name", dataType: "string", width: "250", dataIndx: 4},
                { title: "Country", dataType: "string", width: "100", dataIndx: 6 },
                { title: "InActive", dataType: "string", width: "100", dataIndx: 2 }
                ];

                var dataModelhl = {
                    //cache: true,
                    location: "remote",
                    dataType: "xml",
                    method: "POST",
                    getUrl: function () {
                        return {
                            url: "@Url.ModuleUrl().Action("AccessHotelList")",
                            data: { 'id': ctr }
                        };
                    },
                    getData: function (dataDoc) {
                        //debugger;

                         var obj = { itemParent: "BriefAccommodationInfo", itemNames: ["code", "name", "inactive", "resortCode", "resortName", "countryCode", "countryName"] };
                        return { data: $.paramquery.xmlToArray(dataDoc, obj) };
                    }
                };


                var obj = {
                    width: 750, height: 0,
                    dataModel: dataModelhl,
                    colModel: colModelhl,
                   
                    pageModel: { rPP: 10, type: "local", rPPOptions: [1, 2, 5, 10, 20, 100] },
                    title: "<b>Hotel List</b>",
                    flexHeight: true,
                    paging: true,
                    draggable: false,
                    editable: false,
                    //resizable:true,           
                    scrollModel: { horizontal: false },
                    numberCell: false,
                    selectionModel: {
                        type: 'row', mode: 'single'
                    },
                   

                    collapsible: { on: true, collapsed: false },
                    freezeCols: 0,
                    rowSelect: loadHotel
                };

                $gridhl = $("#HotelGrid").pqGrid(obj);

               $gridhl = $("#HotelGrid").pqGrid("refresh");

lgauton

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #5 on: February 15, 2016, 08:12:14 pm »
Some further info this is the pqgrid.min.js error that is showing in Chrome console

pqgrid.min.js:140 Uncaught TypeError: Cannot read property 'option' of undefined

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #6 on: February 15, 2016, 08:21:22 pm »
If you have been using jQuery 2.x, please apply the patch mentioned here

http://paramquery.com/forum/index.php?topic=1338.msg6154#msg6154

and kindly let me know whether the issue is resolved.

lgauton

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #7 on: February 15, 2016, 09:49:27 pm »
Hi Thanks that fixed the display issue - now getting completed grid but once I add in new sortModel

var sortModelhl = {
                    cancel: false,
                    single: true,
                    type: "local",
                    sorter: [{ dataIndx: "name", dir: "up" }]
                };

i get a new error

pqgrid.min.js:416 Uncaught TypeError: Cannot read property 'sortType' of undefined

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #8 on: February 15, 2016, 11:10:04 pm »
It's answered earlier:

dataIndx in the sortModel.sorter in your code doesn't match with any dataIndx in the colModel.

Code: [Select]
sorter: [{ dataIndx: "name", dir: "up" }]

lgauton

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: Upgrading v2.4 to v3.2
« Reply #9 on: February 16, 2016, 01:57:33 pm »
Thanks all sorted - I was sure that dataIndx - numeric and name were interchangeable