Skip to content
Browse files

Merge branch 'master' of git://github.com/clanceyp/yui3 into clanceyp…

…-master

Conflicts:
	src/datatable/HISTORY.md
  • Loading branch information...
2 parents dc39335 + 85557a2 commit 90e379a0c4b4ff49afddd14187c583b5f6feac36 @ericf ericf committed
View
12 src/datatable/HISTORY.md
@@ -1,10 +1,18 @@
DataTable Change History
========================
+
@VERSION@
----------
+-----
+
+* Avoid processing columns if there aren't any to allow empty tables.
+ [Pull Request #176] [Mark Woon]
-* Pull Req: #176 - Avoid processing columns if there aren't any to allow empty tables [markwoon]
+* Default sort for text columns is now case insensitive. Added `caseSensitive`
+ attribute to table columns config. Setting `caseSensitive` to `true` will
+ bypass the case insensitive sort speeding up sort in large data sets, where
+ case insensitivity is not required. [Ticket #2532134] [Pull Request #281]
+ [clanceyp]
3.8.0
-----
View
59 src/datatable/docs/assets/datatable-sort-tests.js
@@ -46,6 +46,65 @@ YUI.add('datatable-sort-tests', function(Y) {
}
}));
+
+ /* sortable data types test */
+
+ var suiteSortable = new Y.Test.Suite('datatable-sort example test suite'),
+ tableSortableSelector = '#sortSensitive ',
+ ths = Y.all(tableSortableSelector + 'th'),
+ tds = Y.all(tableSortableSelector + 'td'),
+ trs = Y.all(tableSortableSelector + 'tr');
+
+
+
+
+ suiteSortable.add(new Y.Test.Case({
+ name: 'Example sortable tests',
+ 'test click to sort data types': function() {
+ Assert.areEqual('1', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 before sort');
+
+ ths.item(0).simulate('click');
+ tds = Y.all(tableSortableSelector + 'td'); // refresh the nodeList
+ Assert.areEqual('1', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 after Number sort');
+
+ ths.item(0).simulate('click');
+ tds = Y.all(tableSortableSelector + 'td'); // refresh the nodeList
+ Assert.areEqual('4', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 after Number sort');
+
+ ths.item(1).simulate('click');
+ tds = Y.all(tableSortableSelector + 'td'); // refresh the nodeList
+ Assert.areEqual('1', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 after DATE sort');
+
+ ths.item(1).simulate('click');
+ tds = Y.all(tableSortableSelector + 'td'); // refresh the nodeList
+ Assert.areEqual('4', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 after DATE sort');
+
+ // should be AaBbCcZz
+ ths.item(2).simulate('click');
+ tds = Y.all(tableSortableSelector + 'td'); // refresh the nodeList
+ Assert.areEqual('2', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 after String sort');
+
+ ths.item(2).simulate('click');
+ tds = Y.all(tableSortableSelector + 'td'); // refresh the nodeList
+ Assert.areEqual('4', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 after String sort');
+
+ // should be ABCZabcz
+ ths.item(3).simulate('click');
+ tds = Y.all(tableSortableSelector + 'td'); // refresh the nodeList
+ Assert.areEqual('1', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 after String case sensitive sort');
+
+ ths.item(3).simulate('click');
+ tds = Y.all(tableSortableSelector + 'td'); // refresh the nodeList
+ Assert.areEqual('4', tds.item(0).getHTML(), ' - Wrong text in col 1 row 1 after String case sensitive sort');
+
+ ths.item(0).simulate('click');
+ }
+ }));
+
+
+
+
Y.Test.Runner.add(suite);
+ Y.Test.Runner.add(suiteSortable);
}, '', { requires: [ 'node', 'node-event-simulate' ] });
View
24 src/datatable/docs/index.mustache
@@ -1235,6 +1235,10 @@ YUI({ filter: 'raw' }).use('datatable-sort', function (Y) {
<p>
Disable header-click sorting by setting `sortable` to `false`.
</p>
+<p>
+ The default sort order is case insensitive, the sort order can be set to case sensitive
+ by using the `caseSensitive` attribute, see <a href="#column-config">Appendix A</a> below.
+</p>
<h4 id="customsort">Custom Sorting</h4>
@@ -2020,13 +2024,31 @@ pies.on('pie:slicesChange', function (e) {
user sorting by clicking on the header.
</p>
<p>
- If the instance's `sortable` attribute is set, this
+ If the instance's `key` attribute is not set, this
configuration is ignored.
</p>
</td>
<td>`datatable-sort`</td>
</tr>
<tr>
+ <td>caseSensitive</td>
+ <td>
+ ```
+ { key: 'lastLogin', sortable: true, caseSensitive: true }
+ ```
+
+ <p>
+ When the instance's `caseSensitive` attribute is set to
+ "true" the sort order is case sensitive (relevant to string columns only).
+ </p>
+ <p>
+ Case sensitive sort is marginally more efficient and should be considered
+ for large data sets when case insensitive sort is not required.
+ </p>
+ </td>
+ <td>`datatable-sort`</td>
+ </tr>
+ <tr>
<td>sortFn</td>
<td>
```
View
21 src/datatable/docs/partials/datatable-sort-source.mustache
@@ -1,5 +1,7 @@
<div id="sort" class="yui3-skin-sam dt-example"></div>
+<div id="sortSensitive" class="yui3-skin-sam dt-example"></div>
+
<div id="presorted" class="yui3-skin-sam dt-example"></div>
<div id="dblclick" class="yui3-skin-sam dt-example"></div>
@@ -11,6 +13,12 @@ YUI().use("datatable-sort", function (Y) {
{key:"Phone", label:"Not Sortable Column B"},
{key:"Contact", label:"Click to Sort Column C", sortable:true}
],
+ sortableCols = [
+ {key:"Number", label:"Sortable Number", sortable:true},
+ {key:"Date", label:"Sortable Date", sortable:true},
+ {key:"String", label:"Sortable string", sortable:true},
+ {key:"StringSensitive", label:"Sortable string (case sensitive)", sortable:true, caseSensitive:true}
+ ],
/*
dblclickCols = [
{key:"Company", label:"Dblclick to Sort A", sortable:true},
@@ -23,6 +31,12 @@ YUI().use("datatable-sort", function (Y) {
{Company:"Acme Company", Phone:"650-555-4444", Contact:"John Jones"},
{Company:"Industrial Industries", Phone:"408-555-5678", Contact:"Robin Smith"}
],
+ dataSortable = [
+ {Number:1, Date:new Date(2001, 8, 16), String:"A", StringSensitive:"A"},
+ {Number:2, Date:new Date(2003, 8, 16), String:"a", StringSensitive:"a"},
+ {Number:3, Date:new Date(2005, 8, 16), String:"Z", StringSensitive:"Z"},
+ {Number:4, Date:new Date(2007, 8, 16), String:"z", StringSensitive:"z"}
+ ],dt1,dt2;
/*
presortedData = [
{Company:"Acme Company", Phone:"415-555-1234", Contact:"John Jones"},
@@ -37,6 +51,13 @@ YUI().use("datatable-sort", function (Y) {
summary:"Contacts list",
caption:"Table with simple column sorting"
}).render("#sort");
+
+ dt2 = new Y.DataTable({
+ columns:sortableCols,
+ data:dataSortable,
+ summary:"Sortable test data",
+ caption:"Table with column sorting by data type"
+ }).render("#sortSensitive");
/*
dt2 = new Y.DataTable({
View
10 src/datatable/js/sort.js
@@ -493,11 +493,12 @@ Y.mix(Sortable.prototype, {
// extra function hop during sorting. Lesser of three evils?
this.data._compare = function (a, b) {
var cmp = 0,
- i, len, col, dir, aa, bb;
+ i, len, col, dir, cs, aa, bb;
for (i = 0, len = self._sortBy.length; !cmp && i < len; ++i) {
col = self._sortBy[i];
- dir = col.sortDir;
+ dir = col.sortDir,
+ cs = col.caseSensitive;
if (col.sortFn) {
cmp = col.sortFn(a, b, (dir === -1));
@@ -505,7 +506,10 @@ Y.mix(Sortable.prototype, {
// FIXME? Requires columns without sortFns to have key
aa = a.get(col.key) || '';
bb = b.get(col.key) || '';
-
+ if (!cs && typeof(aa) === "string" && typeof(bb) === "string"){// Not case sensitive
+ aa = aa.toLowerCase();
+ bb = bb.toLowerCase();
+ }
cmp = (aa > bb) ? dir : ((aa < bb) ? -dir : 0);
}
}

0 comments on commit 90e379a

Please sign in to comment.
Something went wrong with that request. Please try again.