8000 fix #1629, #1678: add sortStable option · Robothan/bootstrap-table@44cb312 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44cb312

Browse files
committed
fix wenzhixin#1629, wenzhixin#1678: add sortStable option
1 parent 8adae34 commit 44cb312

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/bootstrap-table.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
undefinedText: '-',
293293
sortName: undefined,
294294
sortOrder: 'asc',
295+
sortStable: false,
295296
striped: false,
296297
columns: [[]],
297298
data: [],
@@ -934,6 +935,12 @@
934935
}
935936

936937
if (index !== -1) {
938+
if (this.options.sortStable) {
939+
$.each(this.data, function (i, row) {
940+
if (!row.hasOwnProperty('_position')) row._position = i;
941+
});
942+
}
943+
937944
this.data.sort(function (a, b) {
938945
if (that.header.sortNames[index]) {
939946
name = that.header.sortNames[index];
@@ -954,6 +961,11 @@
954961
bb = '';
955962
}
956963

964+
if (that.options.sortStable && aa === bb) {
965+
aa = a._position;
966+
bb = b._position;
967+
}
968+
957969
// IF both values are numeric, do a numeric comparison
958970
if ($.isNumeric(aa) && $.isNumeric(bb)) {
959971
// Convert numerical values form string to float.

0 commit comments

Comments
 (0)
0