i'm using this code, playing with jack's example:
Code:
var Example = {
init : function(){
var sort = YAHOO.ext.grid.DefaultColumnModel.sortTypes;
// the DefaultColumnModel expects this blob to define columns. It can be extended to provide
// custom or reusable ColumnModels
var cm = new YAHOO.ext.grid.DefaultColumnModel([
{header: "cod", width: 45, sortType: sort.asUCString},
{header: "Name", width: 150, renderer: italic},
{header: "Team", width: 150, renderer: italic},
{header: "Ruolo", width: 100, renderer: italic}
]);
cm.defaultSortable = true;
var schema = {
root: 'stat_calc',
totalTag: 'TotalCount',
id: 'nothing',
fields: ['c','n', 's', 'r']
};
var dm = new YAHOO.ext.grid.JSONDataModel(schema);
dm.getTotalPages = function(){ // this because i don't know haw i can take totalTag var
return 12;
}
dm.initPaging('/2.0/src/stat_calc.php?act=get_stat_calc', 20);
dm.setDefaultSort(cm, 0, 'DESC');
dm.remoteSort = false;
dm.loadPage(1);
// example of custom renderer function
function italic(value){
return '' + value + '';
}
// example of custom renderer function
function change(val, suffix){
suffix = suffix || '';
if(val > 0){
return '<span>' + val + suffix + '</span>';
}else if(val < 0){
return '<span>' + val + suffix + '</span>';
}
return val;
}
// example of custom renderer function
function pctChange(val){
return change(val, '%');
}
// example of custom renderer function, this hideous code was grabbed off the web
function money(mnt) {
mnt -= 0;
mnt = (Math.round(mnt*100))/100;
mnt = (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
return "$" + mnt;
}
// create the Grid
var grid = new YAHOO.ext.grid.Grid('stat-calc-grid', dm, cm);
grid.render();
grid.getSelectionModel().selectFirstRow();
}
}
YAHOO.ext.EventManager.onDocumentReady(Example.init, Example, true);
the json output is:
Code:
{"TotalCount":561,"stat_calc":[{"r":"1","s":"TORINO","n":"ABBIATI Christian","c":"101"},{"r":"1","s":"PALERMO","n":"AGLIARDI","c":"102"},
[...]
{"r":"1","s":"ROMA","n":"CURCI Gianluca","c":"119"}]}
the code works correctly, i have only two questions:
1) why it not correctly display the paging?
Here a screen of results:

there aren't first, prev, next and last page icon arrow, how to set them on?
2) in json output it is passed TotalCount var to take the total row count, but how can i set it in the grid model, using shema in JSONDataModel don't give results...
:cry:
someone could help me?[/img][/code]