Skip to content

Commit 9050598

Browse files
committed
Fix column show/hide caching issue
The pop-up for showing and hiding columns had been caching the selection of columns once it was opened for the first time. When changing the list of columns on the fly this would cause it to still show the old list.
1 parent b5481ac commit 9050598

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

js/dynamic-table.jquery.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@
11851185
" <div class=\"ui-dynamic-table-filter-date-range-start\"></div> " +
11861186
" </div> " +
11871187
" <div> " +
1188-
" <div style=\"padding-top: 3px; color: #ffffff; font-weight: bold\">End Date (<a class=\"ui-dynamic-table-filter-date-range-end-clear\" href=\"javascript:void(0)\">Clear</a>):</div> " +
1188+
" <div style=\"paddingR-top: 3px; color: #ffffff; font-weight: bold\">End Date (<a class=\"ui-dynamic-table-filter-date-range-end-clear\" href=\"javascript:void(0)\">Clear</a>):</div> " +
11891189
" <div class=\"ui-dynamic-table-filter-date-range-end\"></div> " +
11901190
" </div> " +
11911191
" </div> " +
@@ -1508,10 +1508,19 @@
15081508

15091509
var myHtml =
15101510
"<div class=\"ui-dynamic-table-filter ui-dynamic-table-settings\">" +
1511-
" <ul>";
1511+
" <ul></ul>" +
1512+
"</div>";
1513+
1514+
var myPopUp = methods.private_getPopUp(
1515+
aComponent,
1516+
".ui-dynamic-table-settings",
1517+
myHtml
1518+
);
1519+
1520+
var myInnerHtml = "";
15121521

15131522
myColumns.forEach(function(aColumn, aIndex) {
1514-
myHtml +=
1523+
myInnerHtml +=
15151524
"<li>" +
15161525
" <label>" +
15171526
" <input type=\"checkbox\" class=\"ui-dynamic-table-settings-column\" data-index=\"" + aIndex + "\"" + (aColumn.visible ? " checked" : "") + "> " +
@@ -1520,15 +1529,7 @@
15201529
"</li>";
15211530
})
15221531

1523-
myHtml +=
1524-
" </ul>" +
1525-
"</div>";
1526-
1527-
var myPopUp = methods.private_getPopUp(
1528-
aComponent,
1529-
".ui-dynamic-table-settings",
1530-
myHtml
1531-
);
1532+
myPopUp.find("ul").html(myInnerHtml);
15321533

15331534
myPopUp.find(".ui-dynamic-table-settings-column")
15341535
.off("change.dynamicTable")

sample/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
// Initialize table
2525
$("#sample-grid").dynamicTable({
2626
fillParent : false,
27-
showCounter: true
27+
showCounter: true,
28+
changeColumns : true
2829
});
2930

3031
// Define columns

sample/index2.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,14 @@
140140
$("#selected-data").html("You selected <strong>" + aEvent.row.name + "</strong>");
141141
});
142142

143-
// Add event listeners:
144143
$("#sample-grid").on("rowDoubleClick", function(aEvent) {
145144
$("#selected-data").html("You <em>double-clicked</em> <strong>" + aEvent.row.name + "</strong>");
146145
});
147146

147+
$("#change-columns").on("click", function(aEvent) {
148+
$("#sample-grid").dynamicTable("data", myData, myColumns.sort(function(aCol1, aCol2) {return aCol1.name.localeCompare(aCol2.name)}));
149+
});
150+
148151
});
149152

150153
</script>
@@ -194,6 +197,8 @@
194197
<div id="selected-data">&nbsp;</div>
195198
<div id="save-data">&nbsp;</div>
196199

200+
<button type="button" id="change-columns">Change Columns</button>
201+
197202

198203
</body>
199204

0 commit comments

Comments
 (0)