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
Get total rows before grid is rendered
12/12/2011
23:19
Avatar
RustedBucket
Member
Members
Forum Posts: 8
Member Since:
24/09/2011
sp_UserOfflineSmall Offline

Is there a way to get the total rows and set rowNum before the grid is actually rendered? Picking an arbitrary number like 100 is fine for queries returning less than 100 records, but once those go over the rowNum limit no more records are displayed (without paging or dynamic scrolling etc).

The JSON response contains the total number of records contained in the results set, is there a way to read this and use that value to set rowNum so the grid can always display the total number of records without hitting a hard limit?

13/12/2011
09:27
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

I wonder why do you try to resolve everthing with the grid methods. You should have a very simple solution.

Create your own ajax call - this call should ask for the number of recordes (separate one)

In the succes of this ajax call construct your grid with the rowNum obtained from the request.

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.

13/12/2011
18:09
Avatar
RustedBucket
Member
Members
Forum Posts: 8
Member Since:
24/09/2011
sp_UserOfflineSmall Offline

Mostly because everything I've tried so far hasn't worked. You mind giving an example.

I would have assumed according to the doc that beforeProcessing would be a trigger point to do this, but that seems to do nothing at all.

I'd prefer not to call the query a second time just to get something that's already being returned to the grid, I just can't seem to figure out where/how to read it.

13/12/2011
19:38
Avatar
RustedBucket
Member
Members
Forum Posts: 8
Member Since:
24/09/2011
sp_UserOfflineSmall Offline

Figured out the beforeProcessing issue. Wasn't using the latest 4.3 version of the grid which contained the beforeProcessing functions.

I thought this might work but it doesn't.

    beforeProcessing: function(t,data, status, xhr) {
        jQuery.extend(jQuery.jgrid.defaults, { rowNum:t.records });
    },   

14/12/2011
03:39
Avatar
RustedBucket
Member
Members
Forum Posts: 8
Member Since:
24/09/2011
sp_UserOfflineSmall Offline

Tony, ok I got it sort of figured. Here's my code.

$.ajax({
    type: "POST",
    url: "/air/purchases/detailgrid/ponum/" + postData,
    datatype: "json",
    success: function (data, status) {
        var tdata = data.rows;
        var trows = data.records;
        renderGrid(trows, tdata);
    }

});

function renderGrid(trows, tdata) {
    jQuery("#purchases").jqGrid({

        datatype: "local",
        data: tdata,
           height:theight,
           colNames:['Item', 'UPC', 'Description', 'Order Qty.', 'Est. Cost', 'Shipped Qty.', 'Billed Cost'],
           colModel:[
               {name:'item_number',index:'item_number', width:20, align:"center"},
               {name:'upc',index:'upc', width:20, align:"center"},
               {name:'description',index:'description', width:55},
               {name:'order_quantity',index:'order_quantity', width:15, align:"center",formatter: 'integer', formatoptions:{thousandsSeparator: ",", defaultValue: '0'}},
               {name:'order_unit_cost',index:'order_unit_cost', width:15, align:"center",formatter: 'currency', formatoptions:{decimalSeparator:".", thousandsSeparator: ",", decimalPlaces: 2, prefix: "$ "}},
               {name:'shipped_quantity',index:'shipped_quantity', width:15, align:"center",formatter: 'integer', formatoptions:{thousandsSeparator: ",", defaultValue: '0'}},
               {name:'shipped_unit_cost',index:'shipped_unit_cost', width:15, align:"center",formatter: 'currency', formatoptions:{decimalSeparator:".", thousandsSeparator: ",", decimalPlaces: 2, prefix: "$ "}}
           ],
           rowNum: trows,
           rownumbers: true,
           rownumWidth: 40,       
           pager: '#pager',
           altRows: true,
           altclass:'myAltRowClass',
           gridview: true,
        viewrecords: true,
        footerrow: true,
        userDataOnFooter: true,     
        sortorder: "asc",
        autowidth: true,
        shrinkToFit: true   
    
    });
}

The problem now is, the grid display with the correct number of rows, and the JSON data is there in Firebug but all the rows are empty. Any ideas what I'm doing wrong?Thanks

14/12/2011
16:23
Avatar
RustedBucket
Member
Members
Forum Posts: 8
Member Since:
24/09/2011
sp_UserOfflineSmall Offline

Ok think I got it figured out… Here's the modified code of the above…

    $.ajax({
        type: "POST",
        url: "/air/purchases/detailgrid/ponum/" + postData,
        datatype: "json",
        success: function (data, status) {
            var tdata = JSON.stringify(data);
            var trows = data.records;
            renderGrid(trows, tdata);
        }
    });
    
    function renderGrid(trows, tdata) {

        jQuery("#purchases").jqGrid({
    
            datatype: "jsonstring",
            datastr: tdata,

            …

Basically needed to convert the JSON object to a string and pass the whole thing to the grid, then tell the grid to use a JSON string. Works like a champ now.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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