<script id='filteritem' type="text/x-jsrender" >
<span>${getItemTemplate(data)}</span>
</script>
<script>
var dm = [{
id: 0,
text: "New"
},
{
id: 1,
text: "Old"
}];
window.getItemTemplate = function(data) {
if (data.State === 'Select All') {
return data.State;
}
return dm.filter((d) => d.id === data["State"])[0].text;
}
</script>
. . . .
col.Field("State").HeaderText("State").Type("number").Filter(new { type = "CheckBox", itemTemplate="#filteritem" }).Add();
. . . .
|
<script>
function actionbegin(e) {
if (e.requestType === 'filterbeforeopen' && e.columnName === 'State') {
// you can provide custom dataSource (all enum values)
e.filterModel.options.dataSource = [{ State: "New" }, { State: "Old" }, { State:"Latest" }]
}
}
</script>
<div>
@Html.EJS().Grid("Grid").ActionBegin("actionbegin").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).AllowFiltering(true).FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).Columns(col =>
{
. . . . .
col.Field("State").HeaderText("State").Type("number").ValueAccessor("state").Filter(new { type = "CheckBox"}).Width("100").Add();
}).AllowPaging().Render()
</div> |
|
<script id='filteritem' type="text/x-jsrender">
<span>${getItemTemplate(data)}</span>
</script>
<script>
function state(field, data, column) {
var enumText = data[field] == 1 ? "New" : "Old";
return enumText;
};
var dm = [{
id: 1,
text: "New"
},
{
id: 2,
text: "Old"
}];
window.getItemTemplate = function (data) {
if (data.State === 'Select All') {
return data.State;
}
return dm.filter((d) => d.id === data["State"])[0].text;
}
function actionbegin(e) {
if (e.requestType === 'filterbeforeopen' && e.columnName === 'State') {
// custom dataSource
e.filterModel.options.dataSource = [{ State: 1 }, { State: 2}];
e.filterModel.options.filteredColumns = e.filterModel.options.filteredColumns.filter(function (col) {
if (col.field == 'State') {
return true;
}
return false;
})
}
}
</script>
<div>
@Html.EJS().Grid("Grid").ActionBegin("actionbegin").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).AllowFiltering(true).FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").Width("150").Add();
col.Field("State").HeaderText("State").Type("number").ValueAccessor("state").Filter(new { type = "CheckBox", itemTemplate = "#filteritem" }).Width("100").Add();
}).AllowPaging().Render()
</div> |
<script>
. . . . .
function actionbegin(e) {
if (e.requestType === 'filterbeforeopen' && e.columnName === 'State') {
// custom dataSource
e.filterModel.options.dataSource = [{ State: 1 }, { State: 2}];
remove already filtered columns except State
e.filterModel.options.filteredColumns = e.filterModel.options.filteredColumns.filter(function (col) {
if (col.field == 'State') {
return true;
}
return false;
})
}
}
</script>
<div>
@Html.EJS().Grid("Grid").ActionBegin("actionbegin").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).AllowFiltering(true).FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").Width("150").Add();
col.Field("State").HeaderText("State").Type("number").ValueAccessor("state").Filter(new { type = "CheckBox", itemTemplate = "#filteritem" }).Width("100").Add();
}).AllowPaging().Render()
</div> |
<div>
@Html.EJS().Grid("Grid").Created("create").AllowFiltering(true).FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").Width("150").Add();
. . . . . .
col.Field("State").HeaderText("State").Type("number").ValueAccessor("state").Filter(new { type = "CheckBox", itemTemplate = "#filteritem" }).Width("100").Add();
}).AllowPaging().Render()
</div>
<script>
function create() {
class CustomAdaptor extends ej.data.RemoteSaveAdaptor {
onWhere(ds,e){
if (!ds || !ds.length) { return ds; }
return ds.filter((obj) => {
if (e) {
let field = e.isComplex ? e.predicates[0].field : e.field;
// override default filtering for State column.
if (field === 'State') {
let value = parseInt(e.isComplex ? e.predicates[0].value : e.value, 10)
// check whether the filtered value in list of state field.
return obj.State.filter(state => state === value).length !== 0;
} else {
return e.validate(obj); // default filtering
}
}
});
}
}
this.dataSource = new ej.data.DataManager({
// its necessary to provide a json data to bind data to Grid
json: @Html.Raw(Json.Encode(ViewBag.datasource)),
adaptor: new CustomAdaptor()
})
}
</script>
|