jQWidgets Forums

jQuery UI Widgets Forums Grid Get current page rows only

This topic contains 4 replies, has 2 voices, and was last updated by  david_mkd 10 years, 11 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Get current page rows only #57789

    david_mkd
    Participant

    Hello,

    GridView have 3 methods to obtain rows from the grid :
    – getrows
    – getboundrows
    – getdisplayrows

    How can we get the current visible page rows only

    I want to implement the mechanism to select items in grid based on the current page

    Example: 50 items with the split page of 10. I jump to page 2 and I choose only the items shown.

    I try to use the getdisplayrows but it gets more then we are seeing…

    best regards

    Get current page rows only #57790

    Peter Stoev
    Keymaster

    Hi david_mkd,

    getpaginginformation provides information about the current page and page size. The rows on a given page are a subset of getrows or getdisplayrows. This means that you can get the sub array by using the page’s number and its size.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Get current page rows only #57824

    david_mkd
    Participant

    Hi Peter,

    thanks for your sugestion.

    this is my method to do and it works well even with sortable columns:

    
    	SelectPage: function(gridid, b) {
    
    		var pi = $("#" + gridid).jqxGrid('getpaginginformation');
    		var arrSel = $("#" + gridid).jqxGrid('selectedrowindexes').slice();
    		var arrRows = $("#" + gridid).jqxGrid('getrows');
    		var rowsindex = 0
    
    		for (p = 0; p < pi.pagescount; p++) {
    
    			if (p == pi.pagenum) {
    
    				for (r = rowsindex; r < rowsindex + pi.pagesize; r++) {
    
    					if (r < arrRows.length) {
    						if (b) {
    							if ($.inArray($("#" + gridid).jqxGrid('getrowboundindex', r), arrSel) < 0) {
    								$("#" + gridid).jqxGrid('selectrow', $("#" + gridid).jqxGrid('getrowboundindex', r));
    							}
    						}
    						else {
    							$("#" + gridid).jqxGrid('unselectrow', $("#" + gridid).jqxGrid('getrowboundindex', r));
    						}
    					}
    				}
    			}
    
    			rowsindex = rowsindex + pi.pagesize;
    		}
    	},
    

    but this method fails if we use groupable = true when grouped by any column.

    can you help me with that?

    Best regards

    Get current page rows only #57829

    Peter Stoev
    Keymaster

    Hi david_mkd,

    That’s actually the difference between getrows and getdisplayrows. getrows returns the data rows, while getdisplayows returns the rows in the way they’re rendered in the Grid.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Get current page rows only #57856

    david_mkd
    Participant

    Hi Peter,

    thanks again for your support in this issue

    the “getdisplayrows” method do all the work.

    this is the final code to share to people for selecting items on page and it works for sort and group mode enabled:

    
    SelectPage: function(gridid, b) {
    
    	var pi = $("#" + gridid).jqxGrid('getpaginginformation');
    	var arrSel = $("#" + gridid).jqxGrid('selectedrowindexes').slice();
    	var arrDisplayRows = $("#" + gridid).jqxGrid('getdisplayrows');
    
    	/* get only the rowdata */
    	var arrRows = [];
    	for (var rws = 0; rws < arrDisplayRows.length; rws++) {
    
    		if (arrDisplayRows[rws].boundindex != undefined) {
    			arrRows.push(arrDisplayRows[rws]);
    		}
    	}
    
    	/* now we select items on page */
    	var rowsindex = 0
    	var s = "";
    
    	for (p = 0; p < pi.pagescount; p++) {
    
    		if (p == pi.pagenum) {
    
    			for (rr = rowsindex; rr < (rowsindex + pi.pagesize); rr++) {
    
    				if (rr < arrRows.length) {
    
    					if (b) {
    						if ($.inArray($("#" + gridid).jqxGrid('getrowboundindexbyid', arrRows[rr].uid), arrSel) < 0) {
    							$("#" + gridid).jqxGrid('selectrow', $("#" + gridid).jqxGrid('getrowboundindexbyid', arrRows[rr].uid));
    						}
    					}
    					else {
    						$("#" + gridid).jqxGrid('unselectrow', $("#" + gridid).jqxGrid('getrowboundindexbyid', arrRows[rr].uid));
    					}
    				}
    
    			}
    		}
    
    		rowsindex = rowsindex + pi.pagesize;
    	}
    
    

    best regards,

    David

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.