I'm trying to build a sortable grid:
sortBy[data_, idx_] :=
If[idx == 0, data, Sort[data, #1[[idx]] < #2[[idx]] &]];
sortableTable[data_, header_] := DynamicModule[
{h, sort = 0},
h = MapIndexed[Button[#1, sort = #2] &, header];
Dynamic[Grid[Prepend[sortBy[data, sort], h]]]];
sortableTable[
Table[
RandomInteger[100], {i, 3}, {j, 4}],
{"First", "Second", "Third", "Fourth"}]
For some reason it is not behaving like I expected: header disappears and sorting doesn't occur. I've tried all sorts of stuff but can't make it work like intended. Any help is much appreciated.
sort = First@#2
in theMapIndexed
$\endgroup$