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

      0  

    Default Using a renderer on a column doesn't seem to work with sort?

    Using a renderer on a column doesn't seem to work with sort?


    I have a col with the value: float;#300.000000000000
    I am using a renderer to return: '300'

    After I do that, the column sort has no effect on the grid. So I guess my questiosn is does the sortType only refer to the dataModel, and not the rendered data?

    I am using the following

    Code:
    {header: "Avg Hours", width: 120, sortable: true, sortType: sort.asInt, renderer: this.renderTypeFloat},

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    Yes, but you could define a new sortType (other than asInt), which applies your renderer to the data.

  3. #3
    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'm confused as to whats going on? Can you explain further?

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    His data value looks like it's actually on object containing type and value. The renderer returns the value, but sort is probably treating the entire thing as a string so, it probably doesn't make sense if you sort 'float, 300' and 'int,200'.

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

      0  

    Default


    Hi Jack.

    What I have is funky xml that i'm loading into the dataModel. One of the column values is represented as:
    "float;#300.000000000000"


    I am using a renderer function to convert this to "300" as an int:

    Code:
    {header: "Approved Hours", width: 120, sortable: true,sortType: sort.asInt, renderer: this.renderTypeVariant}
    Code:
    renderTypeVariant : function(val){
    		if(val != '')
    			return(parseInt(val.substring(val.indexOf('#')+1)));
    	},
    After doing the render, clicking the column header to sort as an integer does not do any sort at all.

  6. #6
    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


    What you are looking for is preprocessor to reformat funky xml into a valid number. Something like:

    Code:
    // add preprocessor to the second data column
    dataModel.addPreprocessor(2, function(value){
        if(value != ''){
              value = parseInt(value.substring(value.indexOf('#')+1), 10);
        }
        return value;
    });
    The difference is this parses the data as it is coming in and then sort and renderers will both use the parsed value (rather than parsing and/or converting on every sort and/or render).

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

      0  

    Default


    That did the trick!! Thanks Jack. So on that note, when would you use a renderer instead of a pre-processor?

  8. #8
    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 would use a renderer when the data is in the correct format, but you want it rendered differently. For example, your data has the values 1, .5, 2.3, 4.5 and you want them rendered $1.00, $0.50, $2.30 etc. Or another example would be your data contains Date objects and you want them rendered as formatted strings.

Similar Threads

  1. Problem with column sort
    By yevgen in forum Ext 1.x: Bugs
    Replies: 3
    Last Post: 2 Apr 2009, 2:32 AM
  2. Re-render content in resizable column using custom renderer?
    By KimH in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 25 Jun 2008, 8:34 AM
  3. Grid: Post column name (not just id) in remote sort
    By brondsem in forum Community Discussion
    Replies: 2
    Last Post: 18 Feb 2007, 4:01 PM
  4. grid sort marks all rows by the first column
    By lsmith in forum Ext 1.x: Help & Discussion
    Replies: 8
    Last Post: 22 Nov 2006, 9:13 AM
  5. Grid Sort for formatted date column in FF vs IE6
    By mrim in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 31 Oct 2006, 8:28 PM

Thread Participants: 2