[ 5 posts ]

B. Estrade

  • Username: estrabd
  • Joined: Wed Sep 07, 2011 12:28 pm
  • Posts: 49
  • Location: Houston, Texas
  • Twitter: estrabd
  • GitHub: estrabd
  • Gists: estrabd
  • IRC: estrabd
  • Offline
  • Profile

custom sort function via DataTableSort plugin?

Post Posted: Fri Jan 27, 2012 1:11 pm
+1-
I've gotten this far:

Code:
var table = new Y.DataTable.Base({
    columnset: _this.get('columnSet'),
    recordset: e.response.results,
}).plug(Y.Plugin.DataTableSort, {});

var countSort = function(recA, recB, field, desc) {
    var countA = 1*recA.getValue(field); 
    var countB = 1*recB.getValue(field); 
    // return what?
    return .... ??
};

table.get('recordset').sort.sort('count',false,countSort);


I am trying to make a column sort numerically. I can get as far as extracting the values to be compared, but I don't know what to return.

I tried using numerical comparisions and even ArraySort.compare, but both cause the error "T is null".

What's the proper way to set a custom sort function in a YUI 3 DataTable via DataTableSort plugin?

TIA

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: custom sort function via DataTableSort plugin?

Post Posted: Fri Jan 27, 2012 11:49 pm
+1-
Hello B. Estrade.

In the column defintions you may add a "sortFn" attribute, defining a custom sort function:

http://yuilibrary.com/yui/docs/api/file ... s.html#345

I didn't find the documentation. I would debug that line how to see the "sorter" is called and implemented.

Hope that helps,
IceBox

B. Estrade

  • Username: estrabd
  • Joined: Wed Sep 07, 2011 12:28 pm
  • Posts: 49
  • Location: Houston, Texas
  • Twitter: estrabd
  • GitHub: estrabd
  • Gists: estrabd
  • IRC: estrabd
  • Offline
  • Profile
Tags:

Re: custom sort function via DataTableSort plugin?

Post Posted: Sun Jan 29, 2012 8:19 pm
+0-
Thanks, will let you know how it works out.

Brett

Luke Smith

YUI Contributor

  • Username: lsmith
  • Joined: Thu Aug 28, 2008 7:50 am
  • Posts: 507
  • Location: Sunnyvale
  • Twitter: ls_n
  • GitHub: lsmith
  • Gists: lsmith
  • IRC: ls_n
  • YUI Developer
  • Offline
  • Profile

Re: custom sort function via DataTableSort plugin?

Post Posted: Mon Jan 30, 2012 1:03 am
+1-
Custom sorting is incompletely implemented in YUI 3.4.1 and prior.

The patch is:
Y.Column.ATTRS.sortFn = {};

This has been fixed in 3.5.0 development. 3.5.0pr2 (preview release 2) will be made available Monday Jan 30th if you want to try it out. Warning: DataTable underwent a major refactor, and some APIs have changed, but hopefully for the better. Documentation will be made available along with the preview release.

B. Estrade

  • Username: estrabd
  • Joined: Wed Sep 07, 2011 12:28 pm
  • Posts: 49
  • Location: Houston, Texas
  • Twitter: estrabd
  • GitHub: estrabd
  • Gists: estrabd
  • IRC: estrabd
  • Offline
  • Profile

Re: custom sort function via DataTableSort plugin?

Post Posted: Mon Jan 30, 2012 1:33 pm
+0-
Thanks, Luke!

I added your patch near above my table instantiation/DataTableSort plugin.

I then added the "sortFn" attribute to my columns definition:

Code:
        var columnSet = [{
            label: "Counts",
            key: "count",
            parser: Y.DataType.Number.parse,
            sortable: true,
            sortFn: function(a, b, field, desc) {                                                                   
                var aCount = 1.0 * a.getValue(field);                                                                     
                var bCount = 1.0 * b.getValue(field);                                                                     
                // ties go to aCount
                return (aCount > bCount) ? desc: ! desc;                                                                 
        }];


Hope that helps others, feedback is welcome.
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum