How to assign the data dynamically to jqGrid?
Asked Answered
I

1

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);
Isogamy answered 25/1, 2012 at 11:32 Comment(3)
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.Gallaher
@Oleg, i have tried your approach also. But it didn't work as expected.It displayed the updated results and also the previous data.Isogamy
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.Gallaher
G
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.

Gallaher answered 25/1, 2012 at 11:39 Comment(2)
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.Isogamy
@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.Gallaher

© 2022 - 2024 — McMap. All rights reserved.