Results 1 to 3 of 3

Thread: New params in store nad PagingToolbar

  1. #1
    Ext User ExtSwede's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    34

    Default New params in store nad PagingToolbar

    Hi, I have a question regarding paging toolbars.

    I have a store with some params. One for example is status which is empty the first time the grid is loaded. Then I have a filter that the user may choose a status and then the grid loads again with only that status. But when I'm clicking the next page the status is once more empty.

    How do you pass along the param that the store was loaded with previously? My value is global so that isn't the problem. Don't know if you need any code at this point, if you do let me know and I'll post it.

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Code:
    store.setBaseParam('status', myStatus);
    store.load({params: {start: 0, limit: 20}});

  3. #3
    Ext User ExtSwede's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    34

    Default

    Hi Condor

    Tried using setBaseParam before any of the store.load I have, but then I get "Object doesn't support this property or object"

    I post the code, perhaps it helps finding where the problem lies..

    Code:
    var Tender = {};
    var Page = function() {
     var db, ext;
     
     var isTeamRequested;
     var isPrintable;
     
     var strSortField;
     var strSortOrder
     
     var gStore;
     var grid;
     var tenderstock;
     var selected;
     var strStatus;
     var tendersearch;
     var query;
     
     var TENDER_SERVLET, TENDER_SEARCH;
     var strType;
     var strOrgKey;
     var REC_START;
     var REC_LIMIT;
     return {
      init: function() {
      
       db = Session.CurrentDatabase.WebFilePath;
       ext = Session.Ext.ReplicaID;
       var rid = Session.CurrentDatabase.ReplicaIDLS;
       
       Ext.get('tenderstock').setStyle('visibility', 'hidden');
       
       Ext.QuickTips.init();
       
       Ext.BLANK_IMAGE_URL = '/'+ext+'/extjs/resources/images/default/s.gif';
       Tender = parent.Tender;
       isTeamRequested = (Ext.getDom('Selected').value=='Team') ? true : false; 
       isPrintable = (Ext.getDom('Print').value=='true') ? true : false;
       strSortField = Ext.getDom('SortField').value;
       strSortOrder = Ext.getDom('SortOrder').value;
       selected = Ext.getDom('Selected').value;
       //query = Ext.getDom('SearchField').value;
       //query = document.forms[0].searchField.value;
       TENDER_SERVLET = '/tomcat_tender-web/servlet/TenderList';
       //TENDER_SEARCH = '/tomcat_tender-web/servlet/TenderSearch';
       //var STOCK_AGENT  = '/'+db+'/TenderStock.json?OpenAgent';
       var STOCK_SERVLET  = '/tomcat_tender-web/servlet/TenderStock';
       var CELL_INDEX_DELETE = 10;
     
       //var GRID_WIDTH = 775;
       var GRID_HEIGHT = Ext.lib.Dom.getViewHeight() - 115; //155
       var GRID_WIDTH = Math.max(775, Ext.lib.Dom.getViewWidth()-20);
     
       REC_START = 0;
       REC_LIMIT = 100;
       var img_lock = "<img src='img/lock.gif?OpenImageResource'>";
       var img_group = "<img src='img/group.gif?OpenImageResource'>";
       var img_del = "<img src='img/miniIconDel.gif?OpenImageResource'>";
       var status = Ext.select('input.status');
       status.on('click', Page.onStatusChange.createDelegate(this, [status], false) );
       if( !isPrintable ) { 
        strOrgKey  = Tender.curOrgKey;
        var strTeamKey = Tender.curTeamKey;
        strType = (selected=='Organization') ? Session.User.Type : Session.Team.Type;
       } else {
        strOrgKey  = Ext.get('OrgKey').dom.value;
        var strTeamKey = Ext.get('TeamKey').dom.value;
        strType    = Ext.get('Type').dom.value;
        strStatus = Ext.get('Status').dom.value;
       }
       strOrgKey = (selected=='Organization' || selected=='') ? strOrgKey : '';
       strTeamKey = (selected=='Team') ? strTeamKey : '';
       gStore = new Ext.data.Store({
        remoteSort: true,            
          proxy: new Ext.data.HttpProxy(
               new Ext.data.Connection({
          url: TENDER_SERVLET,   
          method: 'POST',
          timeout: 120000,
          extraParams: { Status: Page.test(), query: query, rid: Session.CurrentDatabase.ReplicaIDLS, OrgRID: Session.OtherDb.OrgDb, Type: strType, orgkey: strOrgKey, TeamKey: strTeamKey}
         })
        ),
        reader: new Ext.data.JsonReader({
         totalProperty: 'total',
         root: 'tenders'
        }, [
         {name: 'unid', type: 'string'},
         {name: 'orgKey', type: 'string'},
         {name: 'tenderStatus', type: 'string'},
         {name: 'readerControl', type: 'string'},
         {name: 'tenderNumber', type: 'string'},
         {name: 'tenderResponsible', type: 'string'},
         {name: 'companyNameList', type: 'string'},
         {name: 'objectName', type: 'string'},
         {name: 'expireDate', type: 'date', dateFormat: 'Y-m-d'},
         {name: 'tenderDate', type: 'date', dateFormat: 'Y-m-d'},
         {name: 'sellingPrice', type: 'string'},
         {name: 'businessCat', type: 'string'},
         {name: 'delete', type: 'string'},
         {name: 'grossmargin', type: 'int'}
        ]),
        
        listeners: {
         'loadexception': function(proxy, options, response, e) {
          Ext.Msg.alert('Felmeddelande', 'Ett fel uppstod. Kontakta IT-Supporten');
         }
        }
          });
          gStore.setDefaultSort('TenderStatus', 'asc');
          if( !isPrintable ) {
          
           tenderstock = new Ext.Panel({
         renderTo: Ext.getBody(),
         width: 775,
         autoHeight: true,
         title: 'Anbudsstock',
         collapsible: true,
         collapsed: true,
         contentEl: 'tenderstock',
         frame: true,
         style: 'margin: 10px',
         tools: [{
          id: 'help',
          qtip: 'Hjälp & ikonförklaring',
          handler: Page.showHelp
         }],
         
         listeners: {
          'expand': function() {
           if(grid) {Page.resyncGridHeight(true);};
          },
          'collapse': function() {
           if(grid) {Page.resyncGridHeight(false);};
          }
         }
        }); 
        tendersearch = new Ext.Panel({
         renderTo: Ext.getBody(),
         width: 775,
         autoheight: true,
         collapsible: true,
         collapsed: true,
         title: 'Anbudsfiltrering',
         contentEl: 'tendersearch',
         frame: true, 
         style: 'margin: 10px',
         tools: [{
          id: 'help',
          qtip: 'Hjälp för sökning',
          handler: Page.showSearchHelp
         }],
         
         listeners: {
          'expand': function() {
           if(grid) {Page.resyncGridHeight(true);};
          },
          'collapse': function() {
           if(grid) {Page.resyncGridHeight(false);};
          }
         }
        });
              
           var cm = new Ext.grid.ColumnModel([
                { header: "St.", dataIndex: 'tenderStatus', width: 35, renderer: Util.Format.statusRenderer, sortable: true, menuDisabled: true },
         { header: img_lock, dataIndex: 'readerControl', width: 25, renderer: Util.Format.accessRenderer, align: 'center', menuDisabled: true },
         { header: img_group, dataIndex: 'businessCat', width: 25, renderer: Util.Format.businessRenderer, align: 'center', menuDisabled: true },
         { header: "Anb.nr", dataIndex: 'tenderNumber', width: 80, sortable: true, menuDisabled: true },
         { header: "Ansv.", dataIndex: 'tenderResponsible', width: 52, sortable: true, menuDisabled: true },
         { header: "Kund", dataIndex: 'companyNameList', width: 185, menuDisabled: true, sortable: true },
         { header: "Anl/objekt", dataIndex: 'objectName', width: 100, menuDisabled: true },
         { header: "Pris", dataIndex: 'sellingPrice', width: 50, align: 'right', renderer: Util.Format.thousandSeparator, menuDisabled: true },
         { header: "Projektmarginal", dataIndex: 'grossmargin', width: 50, align: 'right', sortable: true, menuDisabled: true },
         { header: "Anbudsdatum", dataIndex: 'tenderDate', width: 90, align: 'center', renderer: Ext.util.Format.dateRenderer('Y-m-d'), menuDisabled: true },
         { header: "Giltig t.o.m.", dataIndex: 'expireDate', width: 90, align: 'center', renderer: Ext.util.Format.dateRenderer('Y-m-d'), menuDisabled: true },
         { header: img_del, dataIndex: 'delete', width: 20, renderer: Util.Format.deleteRenderer, align: 'center', menuDisabled: true}
               ]);
              
               cm.defaultSortable = false;
      
        grid = new Ext.grid.GridPanel({
       
         width: GRID_WIDTH,
                height: GRID_HEIGHT,
                style: 'margin: 10px',
                title: 'Aktuella Anbud',
                renderTo: Ext.getBody(),
                id: 'tendergrid',
                loadMask: {msg: 'Laddar anbudsdata (vänta)...'},
                          
                store: gStore,
                cm: cm,
                
                viewConfig: {
          forceFit: true
         },
         bbar: new Ext.PagingToolbar({
          store: gStore,
          pageSize: REC_LIMIT,
          displayInfo: true,
          displayMsg: 'Visar anbud {0} - {1} av {2}',
          emptyMsg: "Inga anbud att visa",
         
          items: ['-', {
           pressed: true,
           icon: 'images/print.gif?OpenImageResource',
                  text: '&nbsp;Skriv ut&nbsp;',
                  cls: 'x-btn-text-icon details',
                  handler: Page.onPrintPage
          },'-', {
           pressed: true,
           icon: 'images/form_edit.gif', 
                  text: '&nbsp;Nytt anbud&nbsp;',
                  cls: 'x-btn-text-icon details',
                  handler: Page.onNewTender
          }]
         }),
            
         listeners: {
          'cellclick': function(grid, row, cell, e) {
             
           var r = grid.getStore().getAt( row );
           var unid = r.get('unid');
           if( cell != CELL_INDEX_DELETE ) {
            location.assign("/" + db + "/0/" + unid + "?EditDocument&Ref="+escape(location.href));
           }       
          }
         }
       
        });
        Ext.Ajax.request({
        method: 'GET',
        url: STOCK_SERVLET,
        params: { rid: rid, type: strType, orgkey: strOrgKey, teamkey: strTeamKey },
        success: function(o) {
         var json = Ext.decode(o.responseText);
         if(json.success) {
          var tpl = Ext.XTemplate.from('tenderstock');
          tpl.overwrite( tenderstock.body, json.data );
         } else {
          Ext.Msg.alert('Felmeddelande',json.message||"def");
         }
        },
        failure: function(o) {
         Ext.Msg.alert('Error','Kunde inte ladda anbudsstock');
        }
       });
              
       } else {
      
        Ext.get('tenderstock').remove();
        gStore.setDefaultSort( strSortField, strSortOrder );
        gStore.on('load', Page.createPrintableTable, this, true );
      
        REC_LIMIT = 9999;
      
       }
       
       
       gStore.load( { params: { start: REC_START, limit: REC_LIMIT, Status: strStatus, query: query }} ); //no
       
       //Updates the grid with values if any checkbox is checked
       if(strStatus != ''){
        gStore.load({ params:{ start: REC_START, limit: REC_LIMIT, Status: strStatus, query: query } }); //no
       }else{
        gStore.removeAll();
        //pbt.updateInfo(); //pagingtoolbar
       }
       
       Ext.EventManager.onWindowResize(function() {
        var width = Math.max(775, Ext.lib.Dom.getViewWidth()-20);
        grid.setWidth(width);
        Page.resyncGridHeight(!tenderstock.collapsed);
       });
         
      },
      
      onStatusChange: function(status) {
       
       strStatus = ''; 
       status.each( function( el, s, index ) {
        if( el.dom.name=='status' ) {
         if( el.dom.checked ) {
         
          if(strStatus == '') {
           strStatus = el.dom.value;
          } else {
           strStatus += ";" + el.dom.value;
          }
          //strStatus += el.dom.value + ";" ;
         }
        }
       });
       
       //gStore.proxy = proxy; //proxy is undefined
       
       //Updates the grid with values if any checkbox is checked
       if(strStatus != ''){
        gStore.load({ params:{ start: REC_START, limit: REC_LIMIT, Status: strStatus, query: query } });
       }else{
        gStore.load({ params:{ start: REC_START, limit: REC_LIMIT, Status: strStatus, query: query } });
        //gStore.removeAll();
        //ptb.updateInfo();
       } 
      },
      
      resyncGridHeight: function(expanded) {
       var height = Ext.lib.Dom.getViewHeight();
       
       var expanded1 = tenderstock.collapsed;
       var expanded2 = tendersearch.collapsed;
       if((expanded1 == false) && (expanded2 == false)) {
        height -= 225; //210
       }else if((expanded1 == false) && (expanded2 == true)) {
        height -= 185; //170
       }else if((expanded1 == true) && (expanded2 == false)) {
        height -= 135; //120
       } else {
        height -= 115;
       }
       
       /*if(expanded) {
        height -= 170; //225
       } else {
        height -= 100; //155
       }*/
       grid.setHeight(height);
      },
       
      /**
       *
       */
      onNewTender: function() {
       var strUrl = '/' + db + '/Tender?OpenForm&key=' + Tender.curOrgKey;
       location.assign( strUrl );
      },
      
      /**
       *
       */
      onPrintPage: function() {
      
       var oSortInfo = gStore.getSortState();
       strSortOrder = oSortInfo.direction;
       strSortField = oSortInfo.field;
       var strURL = window.location
        + ((!isTeamRequested) ? '&orgkey='+Tender.curOrgKey : '&TeamKey='+Tender.curTeamKey)
        + '&Type=' + Session.User.Type
        + '&SortOrder=' + strSortOrder
        + '&SortField=' + strSortField
        + '&Print=true';
      
       window.open( strURL )  
      
      },
      
      /**
       *
       */
      createPrintableTable: function() {
      
       var tpl = new Ext.XTemplate('<tr class="{cls}">',
        '<td>{imgTenderStatus}</td>',
        '<td>{imgReaderControl}</td>',
        '<td>{tenderno}</td>',
        '<td>{tenderresp}</td>',
        '<td>{companynamelist}</td>',
        '<td>{objectname}</td>',
        '<td>{sellingprice}</td>',
        '<td>{tenderdate}</td>',
        '<td>{expiredate}</td>',
        '</tr>'
       );
       
       tpl.compile();
       
       for( i=0; i<gStore.getCount(); i++ ) {
       
        var r = gStore.getAt(i);
        tpl.append( Ext.get('print-template'), {
         cls: (i%2 == 0) ? 'TableRowEve)n' : 'TableRowOdd',
         imgTenderStatus: Util.Format.statusRenderer(r.get('tenderStatus')),
         imgReaderControl: Util.Format.accessRenderer(r.get('readerControl')),
         tenderno: r.get('tenderNumber'),
         tenderresp: r.get('tenderResponsible'),
         companynamelist: Ext.util.Format.ellipsis(r.get('companyNameList'), 30),
         objectname: Ext.util.Format.ellipsis(r.get('objectName'), 30) ,
         expiredate: Ext.util.Format.date( r.get('expireDate'), 'Y-m-d'),
         tenderdate: Ext.util.Format.date( r.get('tenderDate'), 'Y-m-d'),
         sellingprice: Util.Format.thousandSeparator(r.get('sellingPrice'))
        });
       
       }
      
       Ext.get('print-container').setStyle('display', 'block');
      
       window.print();
      
      },
      
      showHelp: function() {
      
       var win = new Ext.Window({
        title: 'Hjälp',
        width: 300,
        height: 350,
        closable: false,
        plain: true,
        layout: 'fit',
        border: false,
        modal: true,
        resizable: false,
                               
        buttons: [{ 
         text: 'OK',
         scope: this,
         handler: function() {
          win.hide();
         }
        }],
        
        items: [{
         bodyStyle: 'padding:10px',
         html: '<table width="100%" border="0" class="x-form-item">'+
           '<tr><td><img src="img/miniSquareOrange.gif?OpenImageResource"></td><td>=</td><td>Prospekt</td></tr>'+
           '<tr><td><img src="img/miniSquareYellow.gif?OpenImageResource"></td><td>=</td><td>Registrerad</td></tr>'+
           '<tr><td><img src="img/miniSquareGreen.gif?OpenImageResource"></td><td>=</td><td>Anbud lämnat</td></tr>'+
           '<tr><td><img src="img/miniSquareRed.gif?OpenImageResource"></td><td>=</td><td>Giltighetstid utgått</td></tr>'+
           '<tr><td><img src="img/miniSquareBlack.gif?OpenImageResource"></td><td>=</td><td>Vilande</td></tr>'+
           '<tr><td><img src="img/miniSquareTurquoise.gif?OpenImageResource"></td><td>=</td><td>No Bid</td></tr>'+
           '<tr><td><img src="img/miniSquareWhite.gif?OpenImageResource"></td><td>=</td><td>Ingen affär</td></tr>'+
           '<tr><td><img src="img/miniSquareBlue.gif?OpenImageResource"></td><td>=</td><td>Vunnen</td></tr>'+
           '<tr><td><img src="img/miniSquareGrey.gif?OpenImageResource"></td><td>=</td><td>Förlorad</td></tr>'+
           '<tr><td><img src="img/lock.gif?OpenImageResource"></td><td>=</td><td>Lässkyddad</td></tr>'+
           '<tr><td><img src="img/group.gif?OpenImageResource"></td><td>=</td><td>Gemensam YIT-affär</td></tr>'+
           '<tr><td><img src="img/miniIconDel.gif?OpenImageResource"></td><td>=</td><td>Ta bort</td></tr>'+
          '</table>'+
          '<br>Siffror i <b>fetstil</b> är anbud med status "anbud lämnat"'
        }]
       });
       
       win.show();
      
      },
      
      showSearchHelp : function() {
       Ext.Msg.alert("Hjälp", "I sökfältet kan du söka på anbudsnummer, objektnamn och kund.");
      },
      
      deleteTender: function(tenderno, companynamlist, orgkey, unid) {
      
       var message = '[ ' + tenderno + ' - ' + companynamlist + ' ]. Detta kommer att raderas. Vill du fortsätta?';
       Ext.Msg.confirm('', message, function(btn) {
        if(btn=='yes') {
         var url = "/" + db + "/DeleteDoc?OpenAgent&unid=" + unid + "&key=" + orgkey;
         window.location.assign( url );
        }
       });
      },
      search: function() {
       query = document.getElementById('searchField').value;
       gStore.load({params: { start: REC_START, limit: REC_LIMIT, query: query, rid: Session.CurrentDatabase.ReplicaIDLS, Status: strStatus, orgkey: strOrgKey } })
      },
      test: function() {
       return strStatus;
      }    
     };
    }();
    Ext.onReady( Page.init );
    function key() {
     if(window.event.keyCode == 13) {
      Page.search();
     }
    }

Similar Threads

  1. PagingToolbar and store POST method JSON params
    By rvanheel in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 23 Jul 2010, 1:47 AM
  2. Ext.PagingToolbar how to set the params for the store dynamically ?
    By ansis_si in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 25 May 2008, 10:02 AM
  3. Replies: 2
    Last Post: 13 Feb 2008, 5:18 PM
  4. PagingToolbar bug when loading store with params
    By matjaz in forum Ext 1.x: Bugs
    Replies: 3
    Last Post: 25 Jun 2007, 12:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •