我使用下面的代码在div标签内加载光滑的网格,它是 工作正常,但我想在光滑网格中发挥更多功能。 如何在单击按钮中删除所有过滤器?
function LoadSlickGrid(txtHRMFilter) {
$(function () {
//debugger;
var data = [];
$.ajax({
url: '/Home/GetDetails/?strHRMFilter=' + txtHRMFilter,
dataType: "json",
type: "POST",
async: false,
contentType: "application/json",
success: function (result) {
data = result.desc;
}
});
var dataView = new Slick.Data.DataView();
grid = new Slick.Grid("#grid", dataView, columns, options);
grid.setSelectionModel(new Slick.CellSelectionModel());
dataView.onRowCountChanged.subscribe(function (e, args) {
grid.updateRowCount();
grid.render();
});
dataView.onRowsChanged.subscribe(function (e, args) {
grid.invalidateRows(args.rows);
grid.render();
});
dataView.beginUpdate();
dataView.setItems(data);
dataView.setFilter(filter);
dataView.endUpdate();
dataView.refresh();
var filterPlugin = new Ext.Plugins.HeaderFilter({});
filterPlugin.onFilterApplied.subscribe(function () {
dataView.refresh();
grid.resetActiveCell();
var status;
if (dataView.getLength() === dataView.getItems().length) {
status = "";
} else {
status = dataView.getLength() + ' OF ' + dataView.getItems().length + ' RECORDS FOUND';
}
$('#status-label').text(status);
});
var pager = new Slick.Controls.Pager(dataView, grid, $("#pager"));
filterPlugin.onCommand.subscribe(function (e, args) {
dataView.fastSort(args.column.field, args.command === "sort-asc");
});
grid.registerPlugin(filterPlugin);
var overlayPlugin = new Ext.Plugins.Overlays({});
// Event fires when a range is selected
overlayPlugin.onFillUpDown.subscribe(function (e, args) {
var column = grid.getColumns()[args.range.fromCell];
// Ensure the column is editable
if (!column.editor) {
return;
}
var value = dataView.getItem(args.range.fromRow)[column.field];
dataView.beginUpdate();
for (var i = args.range.fromRow + 1; i <= args.range.toRow; i++) {
dataView.getItem(i)[column.field] = value;
grid.invalidateRow(i);
}
dataView.endUpdate();
grid.render();
});
grid.setSelectionModel(new Slick.RowSelectionModel({ selectActiveRow: false }));
grid.registerPlugin(checkboxSelector);
grid.registerPlugin(overlayPlugin);
grid.init();
function filter(item) {
var columns = grid.getColumns();
var value = true;
for (var i = 0; i < columns.length`enter code here`; i++) {
var col = columns[i];
var filterValues = col.filterValues;
if (filterValues && filterValues.length > 0) {
value = value & _.contains(filterValues, item[col.field]);
}
}
return value;
}
});
}
--------------------------------
现在我想在slickgrid中使用单击按钮清除所有过滤器。
$("#btnclear").click(function () {
ClearSlickGrid();
});
我怎样才能做到这一点? 在此先感谢。
答案 0 :(得分:1)
您只需设置一个空白过滤器:
$("#btnclear").click(function () {
dataView.setFilter(function(item){
return true;
}
});
如果您想重新申请旧过滤器,请致电:
dataView.setFilter(filter);