PDA

View Full Version : YAHOO.ext.grid : I wan't to enable a button after a refresh



Phil.Strong
25 Jan 2007, 11:14 PM
I am able to enable the button in the render function of my grid however, I want this button to be enabled even if no items are returned. The button is a refresh button. I want it to disable during a refresh and enable after.

I am sure this is obvious but I just can't pin point it. Below is the code I use to setup my grid. I tried to omit anything I thought wasn't important.

I also wanted to know how to add a listener for the delete key, any ideas?
______________________________

var setupGrid = function() {
var sm = new YAHOO.ext.grid.SingleSelectionModel();

var cm = new YAHOO.ext.grid.DefaultColumnModel([
{header: 'Name', width: 150},
{header: 'Description', width: 150},
{header: 'Property', width: 200}
]);
cm.defaultSortable = true;

var dm = new YAHOO.ext.grid.JSONDataModel({
root: 'files',
id: 'id',
fields: ['name', 'description', 'property'],
totalProperty: 'total'
});
dm.setDefaultSort(null, 3, "DESC");

grid = new YAHOO.ext.grid.Grid('myfiles-grid', dm, cm, sm);
grid.view = new YAHOO.ext.grid.PagedGridView();
grid.render();

grid.view.loading.hide();
btnRefresh = grid.view.pageToolbar.addButton({
text: 'Refresh',
tooltip: 'Refresh',
className: 'refresh',
click: grid.view.onClick.createDelegate(grid.view, ['refresh'])
});
grid.view.pageToolbar.addSeparator();

sm.addListener('rowselect', function(row, selected) {
if (!selected){
btnRefresh.enable();
return;
}
btnRefresh.disable();
btnDeleteFile.disable();
task.delay(350, updater.update, updater, ['Controllers/Files.aspx', {'FileID': grid.getSelectedRowId()}]);
}, this, true);


dm.initPaging('Controllers/Files.aspx', 10);
dm.addListener('beforeload', function() {
Minimogl.setStatus('Loading data...', true);
btnRefresh.disable();
btnDeleteFile.disable();
btnNew.disable();

}, this, true);
dm.addListener('load', function() {
Minimogl.setStatus();
grid.selModel.selectFirstRow();
btnNew.enable();
btnRefresh.enable();
}, this, true);
dm.loadPage(1);
};

Phil.Strong
29 Jan 2007, 9:14 PM
bump!

BernardChhun
30 Jan 2007, 5:21 AM
I also wanted to know how to add a listener for the delete key, any ideas?


yourGrid.addListener('keydown', function (e){
var keyCode = e.getCharCode();
console.log(keyCode);
switch(keyCode){
case 13:
alert('this is the enter button');
break;
}
});

use Firebug's console or an alert to check the delete key value and act accordingly.