On this example, column Reference is sorted lexicographically.
<script> /** * Convert french date interval "d/m/Y au d/m/Y" in a string which can be properly compared lexicographically * For example, converts "01/04/2017 au 05/06/2018" to "2017-04-01-2018-06-05" * @param value * @returns {string} */ function convertDateInterval(value) { var matches = value.match(/([0-9]{2}\/[0-9]{2}\/[0-9]{4}) au ([0-9]{2}\/[0-9]{2}\/[0-9]{4})/); var date1Parts = matches[1].split('/'); var date2Parts = matches[2].split('/'); return date1Parts[2] + '-' + date1Parts[1] + '-' + date1Parts[0] + '-' + date2Parts[2] + '-' + date2Parts[1] + '-' + date2Parts[0]; } //Start table fake sort jQuery('.table-fake').fakeTableSortable({ headerItems: 'div.table-fake-row-first > div', lineItems: 'div.table-fake-row', cellItems: 'div.table-fake-col', firstSort: 'asc', sortMethods: ['lexicographical', 'lexicographical', 'lexicographical', 'number'], textConverter: [null, null, convertDateInterval, null] }); </script>
On this example, column Reference is sorted by number value.
The only change from previous example is the sort method applied on the Reference column :
sortMethods: ['lexicographical', 'number', 'lexicographical', 'number']
Label | Amount | ||
---|---|---|---|
Why do you need table sorting anymay ? | 5435346457687768 | 01/04/2017 au 05/04/2018 | 587.23 € |
The quick brown fox jumps over the lazy dog | 5413244546456456 | 01/03/2017 au 05/05/2018 | 768.89 € |
Is this love ? | 35435454656 | 01/04/2018 au 05/04/2019 | 345.87 € |
Yes it is | 223453645765687 | 07/04/2017 au 05/04/2018 | 90.00 € |
On this example, a real table is used.
<script> jQuery('.table-fake3').fakeTableSortable({ headerItems: 'thead > tr > th', lineItems: 'tbody > tr', cellItems: 'td', linesContainer: 'tbody', // This is where you tell where lines are contained firstSort: 'asc', sortMethods: ['lexicographical', 'number', 'lexicographical', 'number'], textConverter: [null, null, convertDateInterval, null] }); </script>