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
Selecting back selected rows when changing the "number of requested rows"
19/01/2009
21:38
Avatar
steph
New Member
Members
Forum Posts: 2
Member Since:
20/01/2009
sp_UserOfflineSmall Offline

Hi,

I wanted to be able to remember the selected rows (multiselect: true) when navigating the grid, I coded the following, which work fine when paginating (first, prev, next, last) and sorting, but doesn't work when changing the "number of requested rows" (select box):

//-----[2 global variables]

/**
 * @var array - currently selected rowids
 */
var selectedRowIds = new Array();

/**
 * @var bool - set to false in method gridComplete
 *             to "disable" method onSelectRow
 *             while it "setSelection" the currently
 *             selected rowids.
 */
var enableOnSelectRow = true;

//-----[2 jqgrid methods]
/**
 * If selected rowid, push it onto "selectedRowIds",
 * If deselected rowid, remove it from "selectedRowIds"
 */
onSelectRow: function(rowid, selected) {
    if ( ! enableOnSelectRow ) {
        return;
    }
   
    if ( selected ) {
        selectedRowIds.push(rowid);
        return;
    }
   
    for( var i in selectedRowIds ) {
        if ( rowid === selectedRowIds[i] ) {
            selectedRowIds.splice(i, 1);
            break;
        }   
    }   
},

/**
 * Iterate over "selectedRowIds" calling
 * "setSelection"
 */
gridComplete: function() {
    enableOnSelectRow = false;
    for ( var i in selectedRowIds ) {
        $('#list').setSelection(selectedRowIds[i]);                  
    }
    enableOnSelectRow = true;
},

If you select some rows and paginate or sort, everything is fine, the selected rows are preserved. If you change the "number of requested rows" (select box), you lose the selected rows until another pagination or sorting is done. Somehow, the "gridComplete" method seams to behave differently when invoked after a "number of requested rows" change, as opposed to a pagination/sorting invocation.

Thank you very much for your help.

Steph

22/01/2009
09:07
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

You can use getGridParam('selarrrow') to get selected rows when in multiselect mode and use onPaging event (which is raised before populate) to store the selected rows

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.

22/01/2009
21:00
Avatar
steph
New Member
Members
Forum Posts: 2
Member Since:
20/01/2009
sp_UserOfflineSmall Offline

Hi Tony,

Thanks for your reply, using onPaging and getGridParam('selarrrow') is the way to go for remembering selected rows, but it doesn't solve the transient problem when  changing the number of rows displayed (e.g. say passing from 10 to 20 rows). The following is a workaround solving the problem (Do a “setSelection”, make sure it's selected, if not, do a “setSelection” again:

onPaging: function() {
    var rows = $('#list').getGridParam('selarrrow');
    for ( var i in rows ) {
        if ( ! array_search(rows[i], selectedRowIds) ) {
            selectedRowIds.push(rows[i]);
        }
    }
},
gridComplete: function() {
    for ( var i in selectedRowIds ) {
        $('#list').setSelection(selectedRowIds[i]);
        /**
         * Workaround: Make sure it's selected, if not, select the row again.
         */
        if ( ! array_search(selectedRowIds[i], $('#list').getGridParam('selarrrow')) ) {
            $('#list').setSelection(selectedRowIds[i]);
        }
    }
},

array_search (equivalent of PHP one, c.f. http://kevin.vanzonneveld.net).

Anyway, it's working with this workaround, but as I wrote in my first message, gridComplete seams to behave differently right after a change in the number of rows displayed (as long as the setSelection function is concerned).

Thanks again Tony for you reply and for this great plugin.

Regards,

Steph

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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