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
Need help for soring in jqGrid
07/03/2012
11:17
Avatar
neerajj
india
New Member
Members
Forum Posts: 2
Member Since:
07/03/2012
sp_UserOfflineSmall Offline

Hi,

I am a newcomer to jqGrid and I am stuck up with sorting in my grid.

Below is my code for jqGrid.The data is displayed properly but still i am not able to sort the columns.

$(function () {
            $("#usrsearchgrid").jqGrid({
                datatype: function (pdata) { getData(pdata); },
                height: 250,
                viewrecords: true,
                pager: jQuery('#pager'),
                loadtext: 'Loading data...',
                recordtext: "{0} - {1} of {2} records",
                emptyrecords: 'No User exists',
                pgtext: 'Page {0} of {1}', //Paging input control text format.
                colNames: ['country', 'emailid', 'firstName', 'lastname'],
                colModel: [
             { name: 'country', width: 150, index: 'country', sortable: true },
             { name: 'emailID', width: 200, index: 'emailID', key: true, sortable: true,sorttype:"string"},
             { name: 'firstName', width: 200, index: 'firstName', sortable: true },
                { name: 'lastName', width: 200, index: 'lastName', sortable: false }
            ],
                sortname: 'emailID',
                sortorder: "desc",
                rowNum: "2", // PageSize.
                caption: "JSON Example"
            });
        });
        function getData(pData) {

            $.ajax({
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                url: 'JQGrid.aspx/getUsers',
                data: '{}',
                dataType: "json",
                success: function (data, textStatus) {
                    if (textStatus == "success")
                        ReceivedClientData(JSON.parse(getMain(data)));
                },
                error: function (data, textStatus) {
                    alert('An error has occured retrieving data!');
                }
            });
        }
        function ReceivedClientData(data) {

            var thegrid = $("#usrsearchgrid");
            thegrid.clearGridData();
            for (var i = 0; i < data.records; i++)
            //grid.jqGrid('addRowData', myData.length + i, newData[newData.length - i - 1], "first");

                thegrid.addRowData(i + 1, data.rows[i]);
        }
        function getMain(dObj) {
            if (dObj.hasOwnProperty('d'))
                return dObj.d;
            else
                return dObj;
        }

Can you please suggest what additions should i make in this..??

07/03/2012
15:34
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

In your case you should done the sorting server side.

See into the docs which parameters are posted when the user click to sort .

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.

07/03/2012
20:28
Avatar
ufalak
New Member
Members
Forum Posts: 2
Member Since:
07/03/2012
sp_UserOfflineSmall Offline

tony said:

Hello,

In your case you should done the sorting server side.

See into the docs which parameters are posted when the user click to sort .

Regards


Im having the same problem.

There is no way to make it from client side?

And if not, how cai i get the parameters from my web service in c#?

09/03/2012
05:54
Avatar
neerajj
india
New Member
Members
Forum Posts: 2
Member Since:
07/03/2012
sp_UserOfflineSmall Offline

Thanks Tony for your help.

I am able to achieve this through server side.

Can you refer a good article or explain what approach I should folow for making the client side sorting work..??

Dear uriel,

In order to get  the column name and the sortorder the you need to mention the column in the ajax call in the below format:

 function getData(pData) {

$.ajax({

type:



'POST',

contentType:



"application/json; charset=utf-8",

url:



'JQGrid.aspx/getUsers',

data:



"{'pSortColumn':'" + $('#usrsearchgrid').getGridParam("sortname") +



"','pSortOrder':'" + $('#usrsearchgrid').getGridParam("sortorder") + "'}",

dataType:



"json",

success:



function (data, textStatus) {



if (textStatus == "success")

ReceivedClientData(JSON.parse(getMain(data)));

},

error:



function (data, textStatus) {

alert(



'An error has occured retrieving data!');

}

});

}

On server side the pSortColumn and pSortOrder will be accessible.





public static string getUsers(string pSortColumn, string pSortOrder);

I think this will help.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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