Author Topic: Is it possible to dynamically change the dataModel?  (Read 338 times)

luckduck

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 46
    • View Profile
Is it possible to dynamically change the dataModel?
« on: December 28, 2023, 07:41:53 am »

In version 8.x, it was used as follows:

Code: [Select]
-- Initial settings
dataModel: {data: []}

-- When clicking the search button
$("#btnSearch").click(function() {
var postData = $(form + " :input").serializeObject();
var dataModel = {
location: "remote",
dataType: "JSON",
method: "POST",
url: $(form).attr("action"),
postData: postData
};

$("#gridDiv").pqGrid("option", "dataModel", dataModel);
$("#gridDiv").pqGrid("refreshDataAndView");
});

However, in version 9.x an error occurs.

pqgrid.min.js:9  Uncaught TypeError: Cannot read properties of undefined (reading 'bind')
    at A.callXHR (pqgrid.min.js:9:62732)
    at A.remoteRequest (pqgrid.min.js:9:63058)
    at A.refreshDataAndView (pqgrid.min.js:9:66110)
    at HTMLDivElement.<anonymous> (jquery-ui.min.js:6:8934)
    at Function.each (jquery-2.2.4.min.js:2:2861)
    at a.fn.init.each (jquery-2.2.4.min.js:2:845)
    at e.fn.<computed> [as pqGrid] (jquery-ui.min.js:6:8817)
    at HTMLDivElement.<anonymous> (uprt.common.js?ver=2022052101:43:17)
    at HTMLDivElement.dispatch (jquery-2.2.4.min.js:3:7537)
    at r.handle (jquery-2.2.4.min.js:3:5620)



In version 9.x, how do the grid display data only when the search button is clicked without searching the data when entering the page?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6307
    • View Profile
Re: Is it possible to dynamically change the dataModel?
« Reply #1 on: December 28, 2023, 01:22:48 pm »
Some of the dataModel sub-options are being unset in your code with $("#gridDiv").pqGrid("option", "dataModel", dataModel) which is causing that error.

Please try this to set only specific dataModel sub-options:

Code: [Select]
  $("#gridDiv").pqGrid("option", "dataModel.url", url );
  $("#gridDiv").pqGrid("option", "dataModel.postData", postData );
  .. and so on.
« Last Edit: December 28, 2023, 07:55:45 pm by paramvir »