Kendo DataSource: How to define “Computed” Properties for data read from remote odata source

前端 未结 3 1062
自闭症患者
自闭症患者 2021-01-15 06:11

Situation:

  • kendo DataSource

    var ordersDataSource = new kendo.data.DataSource({
        type: \"odata\",
        transport: {
            read: {
                    
    
    
            
3条回答
  •  灰色年华
    2021-01-15 06:53

    Here is a way to use calculated field in Kendo Grid.

    var crudServiceBaseUrl = "http://demos.telerik.com/kendo-ui/service",
    dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: crudServiceBaseUrl + "/Products",
                dataType: "jsonp"
            }
        },
        pageSize: 20,
        schema: {
            model: {
                total: function (item) {
                    return this.UnitPrice * this.UnitsInStock;
                }
            }
        }
    });
    
    $("#grid").kendoGrid({
        dataSource: dataSource,
        pageable: true,
        height: 550,
        sortable: true,
        filterable: true,
        toolbar: ["create"],
        columns: [
            { field: "UnitPrice", title: "Unit Price"},
            { field: "UnitsInStock", title: "Units In Stock", width: "120px" },
            { field: "total()", title: "Total" }]
    });
    

提交回复
热议问题