Author Topic: Filter method doesn't work after set dataModel.data  (Read 3362 times)

przemek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 25
    • View Profile
Filter method doesn't work after set dataModel.data
« on: August 06, 2014, 05:15:04 pm »
I try set dataModel.data option and have I a problem.
This is my code:

Code: [Select]
$('div#pqgrid').pqGrid("option", "dataModel.data", response.data);
$('div#pqgrid').pqGrid("refreshDataAndView");
console.log(response.data);
console.log($('div#pqgrid').pqGrid("option", "dataModel.data")); //return null
$('div#pqgrid').pqGrid( "filter", {
data: [
    { oper: 'replace', dataIndx: 'ID', condition: 'contain', value: campaignRef }
]
});


My problem is filter below data setter is not working. (exactly show empty results)
Althought I set dataModel.data the console.log return null.
I thought refreshDataAndView working asynchronous but when I comment filter, console.log with dataModel.data return valid results:

Code: [Select]
$('div#pqgrid').pqGrid("option", "dataModel.data", response.data);
$('div#pqgrid').pqGrid("refreshDataAndView");
console.log(response.data);
console.log($('div#pqgrid').pqGrid("option", "dataModel.data")); //return valid data
//$('div#pqgrid').pqGrid( "filter", {
//data: [
//    { oper: 'replace', dataIndx: 'ID', condition: 'contain', value: campaignRef }
//]
//});

filterModel.type and dataModel.location are "local"

I will be very grateful for help.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Filter method doesn't work after set dataModel.data
« Reply #1 on: August 06, 2014, 09:46:15 pm »
refreshDataAndView refreshes both filter and view.

paramquery.com/pro/tutorial#topic-refreshView

1) So there is no need to call refreshDataAndView in your case since you call filter method just after that.

2) Syntax for filter method is incorrect.

It should be
Code: [Select]
$('div#pqgrid').pqGrid( "filter", {
oper: 'replace',
data: [
    { dataIndx: 'ID', condition: 'contain', value: campaignRef }
]
});
« Last Edit: August 06, 2014, 10:21:20 pm by paramquery »

przemek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Filter method doesn't work after set dataModel.data
« Reply #2 on: August 07, 2014, 02:39:13 pm »
Thanks it works.