Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
JSONString vs. URL
10/11/2009
14:43
Avatar
CaptainPalapa
Member
Members
Forum Posts: 6
Member Since:
10/11/2009
sp_UserOfflineSmall Offline

I see the note:

"If you use a jsonstring to obtain the data - after the data is retrieved the datatype option automatically is set to local - i.e. (currently) the paging will not work!"

I had been hoping, when doing our test setup with jqGrid, that I'd be able to "preload" the first, say, 10 records of a dataset to avoid the inital Ajax call.  Then, using the pager, you'd go to page 2, and the Ajax call would occur.

Is this possible?  Even based on that note, is there a way to override that functionality in some format?  Direct hit to the object, anything?

- WB

10/11/2009
16:53
Avatar
montag
New Member
Members
Forum Posts: 2
Member Since:
11/11/2009
sp_UserOfflineSmall Offline

I was thinking through the same problem last week and i solved it like this. Start out with your datatype set to a function, that loads your initial data via "$table[0].addJSONData(initialResults)", and then make that same function overwrite the datatype property [itself].

var url = "/researchCatalog/Search/ProviderGridData/";
var gridData = getGridData(url, searchParams)
var colModel = gridData.colModel;
var initialResults = gridData.initialResults;
var datatype = function() {
            //there's a little bit of trickery going on in this function
            //so that we can create a jqGrid with initial results,
            //and also hook into all of the auto AJAXy stuff built into the grid
            //when initially creating the grid we use a function as the datatype,
            //but in the function we reset the grids datatype to json
            $table[0].addJSONData(initialResults)
            //reset the datatype variable to json so it will make calls on its own
            $table.setGridParam({ datatype: "json" });

}

        $table.jqGrid({
            url: url,
            datatype: datatype,
            colModel: colModel,
            pagerpos: 'left',
            pager: $("#" + pagerID),
            pgbuttons: true,
            gridComplete: function() {
                RSCat.ContentManager.resizeGrid($table);
            },
        });

11/11/2009
03:48
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

IMHO There is a easy way and the solution is posted here many times

$("#mygrid").jqGrid({

url:'url_to_the_server_json_data',

datatype:'jsonstring'

datastr: actual_string_data_here,

...

})

// If your string data is relative big, make a settimeout to ensure that the new option will work

setTimeout(function() {$("#mygrid").jqGrid('setGridParam',{datatype:'json'}); },50);

// now you are ready to accept server requests

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

11/11/2009
09:29
Avatar
CaptainPalapa
Member
Members
Forum Posts: 6
Member Since:
10/11/2009
sp_UserOfflineSmall Offline

Thanks, Tony.  I had dome quite a bit of searching, but didn't stumble across the answer.

I had actually tried this same concept, unsuccessfully.  I didn't utilize correct format, though, for:

$(”#mygrid”).jqGrid('setGridParam',{datatype:'json'}); 

But definitely working now.  Exactly what I needed!

11/05/2010
00:04
Avatar
macbuoy
Silver Spring, MD
Member
Members
Forum Posts: 24
Member Since:
16/10/2009
sp_UserOfflineSmall Offline

In Tony's solution, will setting the datatype back to "json" work via the gridComplete event like this:

$("#mygrid").jqGrid({

url:'url_to_the_server_json_data',

datatype:'jsonstring'

datastr: actual_string_data_here,

gridComplete: function(){$("#mygrid").jqGrid('setGridParam',{datatype:'json'}); }

});

Is there some reason I should use the setTimeout() instead?

11/05/2010
00:43
Avatar
CaptainPalapa
Member
Members
Forum Posts: 6
Member Since:
10/11/2009
sp_UserOfflineSmall Offline

macbuoy said:

...

Is there some reason I should use the setTimeout() instead?


In my testing, I never needed it.  I just used one of the callback functions (can't remember them now) that after my load, I just flipped it back.  Wasn't any need for the timeout.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
192 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information