ParamQuery grid support forum

General Category => ParamQuery Pro Evaluation Support => Topic started by: kshipra on March 13, 2017, 11:02:16 pm

Title: getData on DataModel referring selector before it is defined ?
Post by: kshipra on March 13, 2017, 11:02:16 pm
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 };
            }
        });



Title: Re: getData on DataModel referring selector before it is defined ?
Post by: paramvir 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.
Title: Re: getData on DataModel referring selector before it is defined ?
Post by: kshipra 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.


Title: Re: getData on DataModel referring selector before it is defined ?
Post by: paramvir 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