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

      0  

    Default adding a new paramater to the post request from a datamodel

    adding a new paramater to the post request from a datamodel


    I wanted to include some filtering support in a paged grid view by also passing a filter variable along with the post request. Here's how I did it.

    Code:
    	dm = new YAHOO.ext.grid.JSONDataModel({
    	    root: 'Users',
    	    totalProperty: "totalCount",
    	    id: 'id',
    	    fields: ['username', 'email', 'level', 'birthday', 'join_date', 'last_login']
    	});
    	dm.initPaging('/ci/admin/users_list', 50);
    	dm.setDefaultSort(cm, 0, 'DESC');
    	grid = new YAHOO.ext.grid.EditorGrid('users_grid', dm, cm);
    	grid.getSelectionModel().clicksToActivateCell = 2;
    	grid.render();
    
    	dm.paramMap['filter'] = 'filter';
    
    	dm.createParams = function(pageNum, sortColumn, sortDir, filter){
    	    var params = {}, map = this.paramMap;
    	    for(var key in this.baseParams){
    	        params[key] = this.baseParams[key];
    	    }
    	    params[map['page']] = pageNum;
    	    params[map['pageSize']] = this.getPageSize();
    	    params[map['sortColumn']] = (typeof sortColumn == 'undefined' ? '' : sortColumn);
    	    params[map['sortDir']] = sortDir || '';
    	    params[map['filter']] = filter || '';
    	    return params;
    	};
    
    	dm.loadPage = function(pageNum, filter, callback, keepExisting){
    	    var sort = this.getSortState();
    	    var params = this.createParams(pageNum, sort.column, sort.direction, filter);
    	    this.load(this.pageUrl, params, this.setLoadedPage.createDelegate(this, [pageNum, callback]), 
    	               keepExisting ? (pageNum-1) * this.pageSize : null);
    	};
    
    	dm.loadPage(1, 'temp');
    This will now send a post request that looks like this -

    Code:
    page=1&pageSize=50&sortColumn=0&sortDir=DESC&filter=temp
    This is just a start, as I'll have to figure out how to carry over that filter value for all the requests to loadPage and such, but figured I'd throw the start out there for anyone else looking to do something similar and trying to find a starting point.

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    I hate to tell you this, but you could have said:

    dm.baseParams['filter'] = 'temp';
    dm.loadPage(1);

    and had the same result. You can add/remove custom parameters using the baseParams object.

    Modifying the signature of loadPage is a bad idea since the signature is expected for internal loading (like the PagedGridView).

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

      0  

    Default


    nope, I'm glad you did tell me As before I quit messing with it for the night, I was looking at everything else I was going to have to change to get it to go through

  4. #4
    Ext User rodiniz's Avatar
    Join Date
    Mar 2007
    Location
    Rio de Janeiro, Brazil
    Posts
    276
    Vote Rating
    0
    rodiniz is on a distinguished road

      0  

    Default


    Or you could use my gridExtensions
    Code:
    /* 
    ©2006 Rodrigo Diniz 
    www.rodrigodiniz.qsh.eu 
    You may use this code in anyway you like but do not remove this copyright 
    */
    //Filter Helper
    YAHOO.ext.grid.Grid.prototype.filter=function(filterCol,filterValue){
        var baseParams={'filtercol': filterCol,'filterValue':filterValue};
        this.dataModel.baseParams = baseParams;
        this.clearSelection();
        this.dataModel.loadPage(1);
    }
    /*
    Helper gets the data in the selected row as an object
    with properties names that match the FIELDS
    */
    YAHOO.ext.grid.Grid.prototype.getRowData=function(){
        var dm = this.dataModel;
        var node = dm.getNode(this.getSelectedRowIndex());
        var fields=dm.schema.fields
        var objRet= new Object();
    
        for(var i=0;i< fields.length;i++){
          objRet[fields[i]]=dm.getNamedValue(node,fields[i]);
        }
        return objRet;
    }
    YAHOO.ext.grid.Grid.prototype.getAllRows=function(){
      var objArray= new Array();
      var dm=this.dataModel;
      var len= dm.getRowCount();
      var fields=dm.schema.fields
        for(var i = 0; i < len; i++){
            var node= dm.getNode(i);
            objRet= new Object();
            for(var j=0;j< fields.length;j++){
              objRet[fields[j]]=dm.getNamedValue(node,fields[j]);
            }
            objArray.push(objRet);
        } 
      return objArray;
    }
    //helper --lets the grid know that no row is selected
    YAHOO.ext.grid.Grid.prototype.clearSelection=function(){
        this.selModel.clearSelections();
    };

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

      0  

    Default


    I did this and it works

    Code:
    	dm.baseParams['filterField'] = '';
    	dm.baseParams['filterValue'] = '';
    
    	var toolbar = grid.getView().getPageToolbar();
    	toolbar.add("Filter");
    	var filterFieldSelect = document.createElement('select');
    	filterFieldSelect.id = 'filterName';
    	var blankOption = document.createElement('option');
    	filterFieldSelect.appendChild(blankOption);
    
    	for (var i = 0, len = cm.config.length; i < len; i++)
    	{
    		var op = document.createElement('option');
    		var opVal = cm.config[i].header;
    		YAHOO.log(opVal);
    		op.value = opVal;
    		op.innerHTML = opVal;
    		filterFieldSelect.appendChild(op);
    	}
    
    	toolbar.add(filterFieldSelect);
    	toolbar.add("by");
    	var filterText = document.createElement('input');
    	filterText.type = "text";
    	filterText.id = "filterVal";
    	toolbar.add(filterText);
    	toolbar.addButton({
    	    className: 'filter',
    	    text: "Go!",
    	    click: function(){
    	    	dm.baseParams['filterField'] = filterFieldSelect.value;
    	    	dm.baseParams['filterValue'] = filterText.value;
    	    	dm.loadPage(1)
    	    }
    	});
    	 
    	dm.loadPage(1);
    Edit: Removed some default values I had set for when I was first setting it up

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

      0  

    Default


    err I could set those 2 strings at the beginning to blank :oops:

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

      0  

    Default baseParams should be highlighted

    baseParams should be highlighted


    Quote Originally Posted by jbowman
    nope, I'm glad you did tell me As before I quit messing with it for the night, I was looking at everything else I was going to have to change to get it to go through
    I spent a evening on finding out how to make my form-based-filter work and fall into a solution:

    1. pick out YAHOO.util.Connect.setForm as a standalone method to process form into a array
    2. set baseParams with the array

    of course, you have to turn your filter into a form before that.

Similar Threads

  1. ds.load GET / POST
    By ealameda in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 23 Apr 2007, 7:52 PM
  2. Help with POST and paging
    By Hillgod in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 6 Mar 2007, 8:06 AM
  3. How do you use yui-ext? Post your screenshots
    By Skeleton in forum Community Discussion
    Replies: 16
    Last Post: 22 Feb 2007, 1:11 AM
  4. asyncRequest POST, but nothing is posted
    By moraes in forum Ext 1.x: Help & Discussion
    Replies: 13
    Last Post: 21 Dec 2006, 4:14 AM
  5. POST with updatemanager and domino?
    By gizzmo in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 18 Dec 2006, 2:55 PM

Thread Participants: 3

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi