1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    58
    Vote Rating
    0
    luke83 is on a distinguished road

      0  

    Default two questions about JSONDataModel and pagingGrid

    two questions about JSONDataModel and pagingGrid


    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]

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Check your resources: You need yui-ext.css and the images.

  3. #3
    Ext User
    Join Date
    Mar 2007
    Posts
    58
    Vote Rating
    0
    luke83 is on a distinguished road

      0  

    Default


    ok.. now it works... 8)

    thx a lot, animal

    but what about the num of rows? there is a way to pass it with json method?

    thx

  4. #4
    Ext User
    Join Date
    Mar 2007
    Posts
    321
    Vote Rating
    0
    jbowman is on a distinguished road

      0  

    Default


    when using JSON, use totalProperty in your datamodel, instead of totalTag, and that should do it.

  5. #5
    Ext User
    Join Date
    Mar 2007
    Posts
    58
    Vote Rating
    0
    luke83 is on a distinguished road

      0  

    Default


    sorry but i don't know how t do it :oops:

    i have the total every time in the php-json call response and i would like to take that value and set it in the data model.. what are the function/method/class i have to look in the documentation?

    thx a lot

  6. #6
    Ext User
    Join Date
    Mar 2007
    Posts
    321
    Vote Rating
    0
    jbowman is on a distinguished road

      0  

    Default


    It's the schema you have set for the datamodel, you have

    Code:
          var schema = {
         root: 'stat_calc',
        totalTag: 'TotalCount',
         id: 'nothing',
         fields: ['c','n', 's', 'r']
     };
    and it should be

    Code:
          var schema = {
         root: 'stat_calc',
        totalProperty: 'TotalCount',
         id: 'nothing',
         fields: ['c','n', 's', 'r']
     };

  7. #7
    Ext User
    Join Date
    Mar 2007
    Posts
    58
    Vote Rating
    0
    luke83 is on a distinguished road

      0  

    Default


    ok, sorry jbowman for the time spend to posting..

    it works now... :roll:

    thx a lot.. 8)

  8. #8
    Ext User
    Join Date
    Mar 2007
    Posts
    321
    Vote Rating
    0
    jbowman is on a distinguished road

      0  

    Default


    no problem, I had the same problem when I switched from xml to json

Similar Threads

  1. Noob questions
    By MacPrawn in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 26 Mar 2007, 2:21 PM
  2. JSONDataModel?
    By kjordan in forum Ext 2.x: Help & Discussion
    Replies: 18
    Last Post: 19 Feb 2007, 2:21 PM
  3. JSONDataModel
    By gizzmo in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 27 Jan 2007, 7:19 AM
  4. More tree questions
    By seldon in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 8 Jan 2007, 5:41 PM
  5. JSONDataModel help
    By khanh3m in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 25 Oct 2006, 4:27 PM

Thread Participants: 2