Forum

July 10th, 2011
You must be logged in to post Login Register

Search Forums:


 






.trigger('reloadGrid') not work.

No Tags
UserPost

12:40
17/10/2012


Bulgarin

Member

posts 3

Post edited 12:41 – 17/10/2012 by Bulgarin


Hello.

I have a problem – My grid can't refresh… I add a button to delete a file from my system. In the end of 'onclick'-method for this button I have

$.ajax({
            url: 'MyPage,
            data: "{}",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8″,
            success: function(data) {
            jQuery("#myJqGrid").jqGrid('setGridParam', { data: data }).trigger('reloadGrid');
            }
        });


And with this I get new data from codebehind method in "MyPage" (this is aspx page). 'data'-object has new values , set it to grid's data, but not refresh the grid with new values.

Can you help me?

Thanks!

15:42
18/10/2012


justinkneff

Member

posts 7

Try adding the following parameters to foce the data type too:

 $('#myJqGrid').setGridParam({ page: 1, datatype: "json" }).trigger('reloadGrid');

19:30
18/10/2012


OlegK

Germany

Member

posts 1210

Post edited 19:38 – 18/10/2012 by OlegK
Post edited 19:39 – 18/10/2012 by OlegK


I suppose that the problem exist because old data values will be not removed by

jQuery("#myJqGrid").jqGrid('setGridParam', { data: data });

The above code works good with empty data, but it could worrk wrong if another (old) data already exist. What you can do is setting the data array using getGridParam:

var referenceToInternalData = jQuery("#myJqGrid").jqGrid("getGridParam", "data");
referenceToInternalData = data;

or just

jQuery("#myJqGrid")[0].p.data = data;

because jQuery("#myJqGrid")[0].p represents the internal parameters of jqGrid.

The reason of the problem is that setGridParam uses jQuery.extend internally (see the source code of jqGrid). One uses

jQuery.extend(true, this.p, {data: data});

So the object {data: data} will be recursively merged with the old options of the grid (with jQuery("#myJqGrid")[0].p). You can read in the documentation of jQuery.extend:

On a deep extend, Object and Array are extended, but object wrappers on primitive types such as String, Boolean, and Number are not.

So the old data values will be merged instead of replacing by setGridParam.


Best regards
Oleg

10:56
15/11/2012


dubeyniraj2010@gmail.com

New Member

posts 1

Hello,


the problem with setGridParam is that it appends parameter values and not replaces to solve this you will have to first set parameter values to null, then reset them with new values.

jq("#list").setGridParam({ postData: null });

jq('#list').setGridParam({ postData: { '_ItemNo': jq('#item').val(), '_Variant': jq('#itemVariant').val() } }).trigger('reloadGrid');

Best Regards,

Niraj



14:45
15/11/2012


destells

New Member

posts 2

Hello.


I had the same problem and I solved it as follow:


jQuery('grid').jqGrid('clearGridData');
jQuery('grid').jqGrid('setGridParam', {data: dataToLoad});
jQuery('grid').trigger('reloadGrid');


Best regards.

No Tags

About the jQuery Grid Plugin – jqGrid forum

Most Users Ever Online:

215


Currently Online:

98 Guests

Forum Stats:

Groups: 1

Forums: 7

Topics: 10277

Posts: 30375

Membership:

There are 11044 Members

There have been 448 Guests

There is 1 Admin

There are 2 Moderators

Top Posters:

OlegK – 1210

markw65 – 179

kobruleht – 144

phicarre – 132

YamilBracho – 124

Renso – 118

Administrators: admin (60 Posts)

Moderators: tony (7389 Posts), Rumen[Trirand] (81 Posts)




Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information