Author Topic: getData on DataModel referring selector before it is defined ?  (Read 3549 times)

kshipra

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 94
    • View Profile
var objoffcar = {
 ----
 dataModel: {
                dataType: "JSON",
                location: "remote",
                recIndx: "Id",
                getUrl: function () {
                    var carId = 1;                   
                    if ($('#ddlCar').val() != null) {
                        carId = $('#ddlCar').val();
                    }

                    return { url: "../Home/LoadOffCar", data: { carId: carId, Type: 3 } }
                },

                getData: function (response) {

                    $gridoffcar.pqGrid("option", "dataModel.data", response.data);
                    return { data: response.data };
                }
            }
        };

       
       var $gridoffcar = $("#grid_offcar").pqGrid(objoffcar);
       var gridoffcar  = $gridoffcar.data("paramqueryPqGrid");

In the options object "objoffcar" the selector grid   is referenced to set data on dataModel . I get error this selector is not defined in getdata function.

  This code is based on sample code on your website. Why are we referring selector before it is defined. I tried setting dataModel after grid is created like shown below. But it is not working. pqgrid.js blows up

 var $gridoffcar = $("#grid_offcar").pqGrid(objoffcar);
    $("#grid_offcar").pqGrid( { dataModel:{ getUrl: function () {
           
            return { url: "../Home/LoadOffCar", data: { carId: carId, Type: 3 } };
        }

        },
            getData: function (response) {

                $gridoffcar.pqGrid("option", "dataModel.data", response.data);
                return { data: response.data };
            }
        });




paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6282
    • View Profile
Re: getData on DataModel referring selector before it is defined ?
« Reply #1 on: March 13, 2017, 11:25:15 pm »
There is no need for  $gridoffcar.pqGrid("option", "dataModel.data", response.data); in getData() callback.

Can you please point out from which demo you got this code.
« Last Edit: March 13, 2017, 11:30:36 pm by paramquery »

kshipra

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 94
    • View Profile
Re: getData on DataModel referring selector before it is defined ?
« Reply #2 on: March 14, 2017, 03:13:57 am »
BatchEditing demo sample code. I used that as base for my grids. Looks like there several ways we can create grid. It  is confusing to see different initialization styles.

Basically I want to send some input from selected dropdown to ajax call in getdata and populate the table.



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6282
    • View Profile
Re: getData on DataModel referring selector before it is defined ?
« Reply #3 on: March 17, 2017, 10:56:49 pm »
getData callback is called by the grid when data has already arrived from server.

Please use postData to send custom variables to the server.

https://paramquery.com/pro/tutorial#topic-loaddata

https://paramquery.com/pro/api#option-dataModel-postData