c1.documentReady(function () {
var theGrid = wijmo.Control.getControl(
'#theGrid'
);
theGrid.childItemsPath =
"cities"
;
theGrid.itemsSource = getData();
document.getElementById(
'filter'
).addEventListener(
'input'
, function (e) {
var filter = e.target.value.toLowerCase();
applyHierarchicalFilter(theGrid, filter);
});
function applyHierarchicalFilter(grid, filter) {
var rows = grid.rows;
for
(var i = 0; i < rows.length; i++) {
var row = rows[i],
state = row.dataItem,
rng = row.getCellRange();
if
(row.level == 0) {
var stateVisible = state.name.toLowerCase().indexOf(filter) >= 0;
if
(stateVisible) {
for
(var j = rng.topRow; j <= rng.bottomRow; j++) {
rows[j].visible =
true
;
}
}
else
{
for
(var j = rng.topRow + 1; j <= rng.bottomRow; j++) {
var city = rows[j].dataItem,
cityVisible = city.name.toLowerCase().indexOf(filter) >= 0;
rows[j].visible = cityVisible;
stateVisible |= cityVisible;
}
rows[i].visible = stateVisible;
}
i = rng.bottomRow;
}
}
}
function getData() {
return
[
{
name:
'Washington'
, type:
'state'
, population: 6971, cities: [
{ name:
'Seattle'
, type:
'city'
, population: 652 },
{ name:
'Spokane'
, type:
'city'
, population: 210 }]
},
{
name:
'Oregon'
, type:
'state'
, population: 3930, cities: [
{ name:
'Portland'
, type:
'city'
, population: 609 },
{ name:
'Eugene'
, type:
'city'
, population: 159 }]
},
{
name:
'California'
, type:
'state'
, population: 38330, cities: [
{ name:
'Los Angeles'
, type:
'city'
, population: 3884 },
{ name:
'San Diego'
, type:
'city'
, population: 1356 },
{ name:
'San Francisco'
, type:
'city'
, population: 837 }]
}
];
}
});