j.Kendo.GridFilter

PHOTO EMBED

Wed Sep 22 2021 13:29:38 GMT+0000 (UTC)

Saved by @rick_m #javascript #c# #telerik #kendo #mvc

function grid_product_filter(element) {
    build_gridfilter(element, '/Products/GridFilterRead');
}


function build_gridfilter(element, url) {
   
    var combobox = element.kendoComboBox({

    placeholder: "Select",
    autoBind: true,
    filter: "contains",

        dataTextField: "Name",
        dataValueField: "Name",

        dataSource: {
            type: "aspnetmvc-ajax",
            sort: { field: "Name", dir: "asc" },
            transport: {
                read: {
                    url: url,
                }
            },
            schema: {
                data: "Data",
                total: "Total"
            },
            pageSize: 200,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true
        }
    });
    setdropdownwidth(combobox);
}
var standardfilterwidth = 300;
function setdropdownwidth(combobox) {
    if (combobox.data("kendoComboBox"))
        combobox.data("kendoComboBox").list.width(standardfilterwidth);
    else if (combobox.data("kendoExtendedComboBox"))
        combobox.data("kendoExtendedComboBox").list.width(standardfilterwidth);
}



content_copyCOPY

c.Bound(x => x.Name).Title("Name").Width(250).Filterable(filterable => filterable.UI("grid_product_filter")); public JsonResult GridFilterRead([DataSourceRequest]DataSourceRequest request) { using (UnitOfWork worker = new UnitOfWork()) { var repository = worker.ProductRepository; var queryable = repository.GetQueryable().Select(s => new { s.Name }).Distinct(); var results = queryable.ToDataSourceResult(request); return results == null ? null : this.Json(results, JsonRequestBehavior.AllowGet); } }