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_Related Related Topics sp_TopicIcon
populate jqgrid with json data
13/05/2011
11:46
Avatar
zalath
Member
Members
Forum Posts: 3
Member Since:
13/05/2011
sp_UserOfflineSmall Offline

Hi,

I'l unabled to populate a jqgrid with json data :

the data :

{ "total": "1","page": "1","records": "9","rows":[ { "id": 1,"cell":[ "1","Davolio","Nancy","F"]}, { "id": 2,"cell":[ "2","Fuller","Andrew","F"]}, { "id": 3,"cell":[ "3","Leverling","Janet","F"]}, { "id": 4,"cell":[ "4","Peacock","Margaret","F"]}, { "id": 5,"cell":[ "5","Buchanan","Steven","F"]}, { "id": 6,"cell":[ "6","Suyama","Michael","M"]}, { "id": 7,"cell":[ "7","King","Robert","M"]}, { "id": 8,"cell":[ "8","Callahan","Laura","M"]}, { "id": 9,"cell":[ "9","Dodsworth","Anne","M"]} ]}

the script :

 function Button1_onclick() {
 
            jQuery(document).ready(function () {
                $('#liste').jqGrid({
                    datatype: function () {
                        $.ajax({
                            url: "WS.asmx/ListeEmployes",
                            data: "{}",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            complete: function (jsondata, stat) {
                                if (stat == "success") {
                                    var thegrid = jQuery("#liste")[0];
                                    var datajson = JSON.parse(jsondata.responseText).d;
                                    thegrid.addJSONData(datajson);
                                    alert(datajson);
                                }
                            }
                        });
                    },
 
                    colNames: ['EmployeeID', 'LastName', 'FirstName', 'empSex'],
 
                    colModel: [
                    {name: 'EmployeeID', index: 'EmployeeID',width: 200},
                    {name: 'LastName', index: 'LastName', width: 200}, 
                    {name: 'FirstName', index: 'FirstName', width: 200},
                    {name: 'empSex', index: 'empSex', width: 100, align: 'center'}
                    ],
 
               
 
                    pager: jQuery('#pager'),
                    rowNum: 10,
                    rowList: [10,20,30],
                    sortname: 'EmployeeID',
                    sortorder: "desc",
                    viewrecords: true,
                    imgpath: 'images',
                    caption: 'My first grid',
 
 
                    jsonReader: {
                    page: "page",
                    total: "total",
                    root: "rows",
                    id: "id",
                    records: "records",
                    repeatitems: false,
                    cell: "cell"
                    },
 
 
                }).navGrid("#pager", { edit: true, add: true, del: true });
            });
        }

the grid is well formated but empty.

I can manually load data in the grid with this script bellow :

jQuery("#a4").click(function () {
                var datarow = { EmployeeID: "10", LastName: "test LN", FirstName: "test FN", empSex: "M" };
                jQuery("#liste").jqGrid('addRowData', 99, datarow);
                 });
Confused

can you tell what I'm doing wrong, 

regards

13/05/2011
13:15
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

You use wrong template code to implement the jqGrid with respect of datatype which is a function. It was needed for very very old versions of jqGrid. jqGrid supports many parameters which allow you to get JSON data from practicaty any sever inclusive ASMX web services.

In the answer for example you will find full working code which shows how you to use ASMX to provide the data for jqGrid.

Best regards
Oleg

13/05/2011
16:14
Avatar
zalath
Member
Members
Forum Posts: 3
Member Since:
13/05/2011
sp_UserOfflineSmall Offline

Thanks for your quick reply

but I've try to follow the sample without success. In fact the "addJSONData" function doesn't seem to care about the passed data.

for example :  thegrid.addJSONData(datajson,null,'nothing') does not throw any error

13/05/2011
16:45
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

What do you mean under "I've try to follow the sample without success". Could you download the example, compile and run it? Is it work? What problems you had? You should understand this to be able to use jqGrid.

The list of disadvantagis of addJSONData is long. Look at here for example. The method addJSONData don't throw any error like all other methods. If you want to see errors you have to implement loadError event handler.

Best regards
Oleg

19/05/2011
20:00
Avatar
zalath
Member
Members
Forum Posts: 3
Member Since:
13/05/2011
sp_UserOfflineSmall Offline

thank you Oleg

It works now although I find the use complex.
I now try to find a solution to synchronize the load on demand feature between client and server sides

best regards

04/04/2014
16:52
Avatar
sadmulwar
Member
Members
Forum Posts: 3
Member Since:
03/04/2014
sp_UserOfflineSmall Offline

I want to update a single row into jqgrid. I have the selected row id and modified data into the JSON formate.
Is this possible that I can update a single row into jqgrid ?

06/04/2014
13:13
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

I'm tottaly confused on what you try to do.

Regards

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.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
47 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