HOT 16.2: updateSettings() wipes Filters conditionCollection
HTML
<script src="https://cdn.jsdelivr.net/npm/handsontable@16.2.0/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable@16.2.0/dist/handsontable.full.min.css">
<p id="status"
style="font-family:sans-serif;font-size:13px;color:#555">
Step 1: Filter "Category" column to show only "A" rows<br>
Step 2: Edit any value in the "Value" column<br>
Step 3: Watch the filter disappear after the simulated server
response
</p>
<div id="example1"></div>
JavaScript
document.addEventListener("DOMContentLoaded", function () {
var container = document.getElementById("example1");
var data = [
{ name: "Alpha", category: "A", value: 10 },
{ name: "Beta", category: "B", value: 20 },
{ name: "Gamma", category: "A", value: 30 },
{ name: "Delta", category: "B", value: 40 },
{ name: "Epsilon", category: "A", value: 50 },
{ name: "Zeta", category: "B", value: 60 },
];
var hot = new Handsontable(container, {
licenseKey: "non-commercial-and-evaluation",
data: data,
colHeaders: ["Name", "Category", "Value (editable)"],
rowHeaders: true,
columns: [
{ data: "name", readOnly: true },
{ data: "category", readOnly: true },
{ data: "value", type: "numeric" },
],
filters: true,
dropdownMenu: true,
columnSorting: true,
stretchH: "all",
afterChange: function (changes, source) {
if (!changes || source !== "edit") return;
// Simulate a server-driven data refresh: in a React app the edit triggers a
// server round-trip; when new data arrives as props the react-wrapper calls
// updateSettings(), which in HOT 17 triggers Filters.updatePlugin() and
// destroys the conditionCollection, wiping all active filter conditions.
var freshData = data.map(function (row) { return Object.assign({}, row); });
setTimeout(function () {
hot.updateSettings({ data: freshData, filters: true });
hot.getPlugin("filters").filter();
}, 600);
},
});
});