stephengolub / rxDataTable

A "catch-all" solution for displaying data in a table format in a basic or extremely complex style.
MIT License
15 stars 8 forks source link

'sort' key should support functions. #40

Open Droogans opened 10 years ago

Droogans commented 10 years ago

This is how it looks now.

'dataField': 'Name',
'sortField': 'Name'

This will use sorting by the data in the data field matching Name. This is because you can have cells with more than one piece of data in it at a time, and you have to sort by one.

'dataField': ['subject', 'ref_no'],
'sortField': 'subject'

I would like it if there was support for more than just strings, but also functions. This is my use case:

'dataField': 'listOfLists'
// [[1], [1, 0], [0, 1], [1], [0], [], [0, 0], [], [1, 1, 0]]
'sortField': function (listOfListsData) { return listOfListsData.length; }
// returns [0, 0, 1, 1, 1, 2, 2, 2, 3]

And for multi-part data cells:

'dataField': ['name', 'description'],
'sortField': function (name, description) {
    return _.contains(name, 'Important') || _.contains(description, 'overdue');
}
stephengolub commented 10 years ago

Love it. I've actually been thinking of moving most of the key munging stuff to just functions. I think it'll be cleaner and more explicit.