| Page 1 of 1 | [ 5 posts ] |
|
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 SantiniYUI Contributor
|
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 |
|
Thanks, will let you know how it works out.
Brett |
|
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. |
|
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. |
| Page 1 of 1 | [ 5 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group