4

Here is my code for creating the jqGrid

$("#ptDataGrid").jqGrid({
                    datatype: 'local',
                    data: arrSpecData,
                    colModel: colmod,
                    rowNum: 10,
                    rowList: [10],
                    pager: '#ptPager',
                    gridview: true,
                    rownumbers: false,
                    viewrecords: true,
                    loadonce:false,
                    hidegrid: false,
                    autowidth: true,
                    caption: 'Crank Pin',
                    height: '100%',
                });

Then i ahve applied some filters on my data and created another array called FilteredData. Now i wanted to assign this new Data source to my grid. I have tried all the approaches i know. But nothing worked. So, How can we assign the new data source to the jqGrid Dynamically? Please suggest some way to assign it.

                dataGrid.setGridParam({ data: filterdData });
                dataGrid[0].refreshIndex();  
                dataGrid.trigger("reloadGrid"); 

Still the same result i am getting :(

Workaround #1:

 $('#divGrid').children().remove();
 $('#divGrid').html(' <table id="ptDataGrid" class="jqgriddata"><tr><td/></tr></table><div id="ptPager"></div> ');  

 createGrid(filterdData,true);
Dinesh
  • 2,026
  • 7
  • 38
  • 60
  • I don't know how you tested my suggestion. In the "UPDATED" part of my answer I appended the lint to the demo which work. – Oleg Jan 25 '12 at 19:19
  • @Oleg, i have tried your approach also. But it didn't work as expected.It displayed the updated results and also the previous data. – Dinesh Jan 25 '12 at 19:37
  • Sorry, but you are wrong! It displays *only updated data*. Just repeat your experiments or look more carefully on my demo. You can save the html page, modify the data from `mydata1` and `mydata2` and see that it really work. – Oleg Jan 25 '12 at 20:21

1 Answers1

5

You can first set new data with respect of setGridParam and then call refreshIndex method (see the answer) to update the internally used _index parameter.

UPDATED: Click on the button "Change data" on the demo to verify that the approach work.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • your demo worked for me, but when i integrated with my code, it gave me the same old issue. I think, i am missing something in my code. I will check. – Dinesh Jan 29 '12 at 06:15
  • @Dinesh: You post only small fragments of the code which you use, so I can't you find the error. jqGrid internally use not more as setting `data` and call `refreshIndex`. So it's correct way. What is exactly not work in your grid? Your error can be in the `colModel` or in the data `arrSpecData` which you use. These are the most important parts of your question. – Oleg Jan 29 '12 at 10:30