PDA

View Full Version : PagedGridView's onclick, and selecting appropriate rows


Animal
11-15-2006, 09:07 AM
First, I propose a new function in SelectionModel: SelectLastRow. There's a selectFirstRow, so I have added this in my yui-ext extensions, I think it should go into the main yui-ext:


/**
* Selects the last row in the grid.
* @param {Boolean} keepExisting (optional) True to retain existing selections
*/
YAHOO.ext.grid.DefaultSelectionModel.prototype.selectLastRow = function(keepExisting){
for(var j = this.grid.rows.length - 1; j >= 0; j--){
if(this.isSelectable(this.grid.rows[j])){
this.focusRow(this.grid.rows[j]);
this.setRowState(this.grid.rows[j], keepExisting);
return;
}
}
};



Now, to my request. The default behaviour is to leave selection undefined, or the same row number on page change. I don't think this is intuitive to the user. On page change, the current selection becomes moot - there should be a definite default.

When going back to the previous screen, I think the view should be scrolled to the bottom with the last row selected, and when going to the next screen, it should select the first row.

Also, refresh should maintain current selection.

So here's my proposed new version of PagedGridView.onClick:


YAHOO.ext.grid.PagedGridView.prototype.onClick = function(which){
var g = this.grid;
var dm = g.getDataModel();
var sm = g.getSelectionModel();
switch(which){
case 'first':
dm.loadPage(1, sm.selectFirstRow.createDelegate(sm));
break;
case 'prev':
dm.loadPage(this.cursor -1, sm.selectLastRow.createDelegate(sm));
break;
case 'next':
dm.loadPage(this.cursor + 1, sm.selectFirstRow.createDelegate(sm));
break;
case 'last':
dm.loadPage(this.lastPage, sm.selectFirstRow.createDelegate(sm));
break;
case 'refresh':
var callback;
// If there is a selection, collect the selected rowIndexes, and
// create an onLoad callback which will re-select those indexes.
if (sm.hasSelection())
{
var selectedRows = sm.getSelectedRows();
var selectedRowIndexes = new Array();
for (var i = 0; i < selectedRows.length; i++) {
selectedRowIndexes.push(selectedRows[i].rowIndex);
}
callback = function(selection, selModel)
{
for (var i = 0; i < selection.length; i++)
selModel.selectRow(selection[i]);
this.focusRow(selection[0]);
}.createDelegate(this, [selectedRowIndexes, sm]);
}
dm.loadPage(this.cursor, callback);
break;
}
};

jack.slocum
11-15-2006, 09:26 AM
That's definitely a user preference. It would drive me insane if the grid scrolled to the bottom (personally).

Animal
11-15-2006, 09:51 AM
On prev page, yes, I see your point.

But on refresh, and other page changes, going to the top is the right thing to do.