Skip to content

Commit 0f3c776

Browse files
committed
fixed sorting Dataset
1 parent 641c5f7 commit 0f3c776

8 files changed

Lines changed: 25 additions & 10 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

modules/.DS_Store

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

modules/wljs-inputs/dist/kernel.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ core.Dataset = async (args, env) => {
10541054
}
10551055

10561056
let thead;
1057+
let updateField = () => {};
10571058

10581059
if (headerCols) {
10591060
thead = document.createElement('thead');
@@ -1102,6 +1103,7 @@ core.Dataset = async (args, env) => {
11021103
page = 0;
11031104
offset = 0;
11041105
viewPort.rebuild(rows, windowSize);
1106+
updateField(page);
11051107
table.scrollTop = 0;
11061108
};
11071109
console.log('sorting call');
@@ -1115,9 +1117,12 @@ core.Dataset = async (args, env) => {
11151117
rows.sort((a, b) => sortDir * compareCells(sortCellValue(a[colIndex]), sortCellValue(b[colIndex])));
11161118
}
11171119
}
1120+
currentPart = 0;
1121+
totalOffset = 0;
11181122
page = 0;
11191123
offset = 0;
11201124
viewPort.rebuild(rows, windowSize);
1125+
updateField(page);
11211126
table.scrollTop = 0;
11221127
});
11231128
thElements.push({th, arrow});
@@ -1258,7 +1263,7 @@ core.Dataset = async (args, env) => {
12581263
totalLength = rows.length;
12591264
totalOffset = 0;
12601265

1261-
const updateField = (page) => {
1266+
updateField = (page) => {
12621267
const current = Math.min((page + 1) * pageSize + totalOffset, totalLength);
12631268
progress.innerText = `${current}/${totalLength}`;
12641269
};
@@ -1270,6 +1275,9 @@ core.Dataset = async (args, env) => {
12701275
paginator.appendChild(prevButton);
12711276
paginator.appendChild(toStart);
12721277

1278+
toStart.classList.add('hidden');
1279+
toEnd.classList.add('hidden');
1280+
12731281
paginator.appendChild(progress);
12741282

12751283
if (env.options) if (env.options.Parts) {

modules/wljs-inputs/dist/kernel.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/wljs-inputs/src/Kernel.wl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,8 @@ DatasetWrapperBox[ l: List[__List], form_ ] := With[{
678678
WLJSTransportSend[req[store[[part]]], Global`$Client ]
679679
],
680680
"Sort"->Function[spec,
681-
Echo[spec];
682681
With[{col = spec[[1]], dir = spec[[2]]},
683-
With[{sorted = If[dir === 0, l, SortBy[l, #[[col]]&, If[dir === -1, ReverseOrder, Order] ] ]},
682+
With[{sorted = Which[dir === 0, l, dir === 1, SortBy[l, #[[col]]& ], True, Reverse @ SortBy[l, #[[col]]& ] ]},
684683
store = splitDataset[sorted];
685684
WLJSTransportSend[req[store[[1]]], Global`$Client ]
686685
]
@@ -712,7 +711,7 @@ DatasetWrapperBox[ l: List[__List], StandardForm] := With[{
712711
],
713712
"Sort"->Function[spec,
714713
With[{col = spec[[1]], dir = spec[[2]]},
715-
With[{sorted = If[dir === 0, l, SortBy[l, #[[col]]&, If[dir === -1, ReverseOrder, Order] ] ]},
714+
With[{sorted = Which[dir === 0, l, dir === 1, SortBy[l, #[[col]]& ], True, Reverse @ SortBy[l, #[[col]]& ] ]},
716715
store = splitDataset[sorted];
717716
WLJSTransportSend[req[store[[1]]], Global`$Client ]
718717
]
@@ -746,7 +745,7 @@ DatasetWrapperBox[ l_List , form_ ] := With[{
746745
],
747746
"Sort"->Function[spec,
748747
With[{col = spec[[1]], dir = spec[[2]]},
749-
With[{sorted = If[dir === 0, l, SortBy[l, #[[col]]&, If[dir === -1, ReverseOrder, Order] ] ]},
748+
With[{sorted = Which[dir === 0, l, dir === 1, SortBy[l, #[[col]]& ], True, Reverse @ SortBy[l, #[[col]]& ] ]},
750749
store = splitDataset[sorted];
751750
WLJSTransportSend[req[store[[1]]], Global`$Client ]
752751
]
@@ -780,7 +779,7 @@ DatasetWrapperBox[ l_List , StandardForm] := With[{
780779
],
781780
"Sort"->Function[spec,
782781
With[{col = spec[[1]], dir = spec[[2]]},
783-
With[{sorted = If[dir === 0, l, SortBy[l, #[[col]]&, If[dir === -1, ReverseOrder, Order] ] ]},
782+
With[{sorted = Which[dir === 0, l, dir === 1, SortBy[l, #[[col]]& ], True, Reverse @ SortBy[l, #[[col]]& ] ]},
784783
store = splitDataset[sorted];
785784
WLJSTransportSend[req[store[[1]]], Global`$Client ]
786785
]
@@ -827,7 +826,7 @@ DatasetWrapperBox[ l : List[__Association] , form_] := With[{
827826
],
828827
"Sort"->Function[spec,
829828
With[{col = spec[[1]], dir = spec[[2]]},
830-
With[{sorted = If[dir === 0, l, SortBy[l, #[assocKeys[[col]] ]&, If[dir === -1, ReverseOrder, Order] ] ]},
829+
With[{sorted = Which[dir === 0, l, dir === 1, SortBy[l, #[assocKeys[[col]] ]& ], True, Reverse @ SortBy[l, #[assocKeys[[col]] ]& ] ]},
831830
store = splitDataset[sorted];
832831
WLJSTransportSend[req[store[[1]]], Global`$Client ]
833832
]
@@ -955,7 +954,7 @@ DatasetWrapperBox[ l : List[__Association] , StandardForm] := With[{
955954
],
956955
"Sort"->Function[spec,
957956
With[{col = spec[[1]], dir = spec[[2]]},
958-
With[{sorted = If[dir === 0, l, SortBy[l, #[assocKeys[[col]] ]&, If[dir === -1, ReverseOrder, Order] ] ]},
957+
With[{sorted = Which[dir === 0, l, dir === 1, SortBy[l, #[assocKeys[[col]] ]& ], True, Reverse @ SortBy[l, #[assocKeys[[col]] ]& ] ]},
959958
store = splitDataset[sorted];
960959
WLJSTransportSend[req[store[[1]]], Global`$Client ]
961960
]

modules/wljs-inputs/src/kernel.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ core.Dataset = async (args, env) => {
10591059
}
10601060

10611061
let thead;
1062+
let updateField = () => {};
10621063

10631064
if (headerCols) {
10641065
thead = document.createElement('thead');
@@ -1107,6 +1108,7 @@ core.Dataset = async (args, env) => {
11071108
page = 0;
11081109
offset = 0;
11091110
viewPort.rebuild(rows, windowSize);
1111+
updateField(page);
11101112
table.scrollTop = 0;
11111113
};
11121114
console.log('sorting call');
@@ -1120,9 +1122,12 @@ core.Dataset = async (args, env) => {
11201122
rows.sort((a, b) => sortDir * compareCells(sortCellValue(a[colIndex]), sortCellValue(b[colIndex])));
11211123
}
11221124
}
1125+
currentPart = 0;
1126+
totalOffset = 0;
11231127
page = 0;
11241128
offset = 0;
11251129
viewPort.rebuild(rows, windowSize);
1130+
updateField(page);
11261131
table.scrollTop = 0;
11271132
});
11281133
thElements.push({th, arrow});
@@ -1264,7 +1269,7 @@ core.Dataset = async (args, env) => {
12641269
totalLength = rows.length;
12651270
totalOffset = 0;
12661271

1267-
const updateField = (page) => {
1272+
updateField = (page) => {
12681273
const current = Math.min((page + 1) * pageSize + totalOffset, totalLength);
12691274
progress.innerText = `${current}/${totalLength}`;
12701275
}
@@ -1276,6 +1281,9 @@ core.Dataset = async (args, env) => {
12761281
paginator.appendChild(prevButton);
12771282
paginator.appendChild(toStart);
12781283

1284+
toStart.classList.add('hidden');
1285+
toEnd.classList.add('hidden');
1286+
12791287
paginator.appendChild(progress);
12801288

12811289
if (env.options) if (env.options.Parts) {

0 commit comments

Comments
 (0)