(kendo)如何在声明性网格定义中指定数据列字段类型

时间:2016-10-31 21:21:41

标签: html xml kendo-ui kendo-grid

我有一个我声明性地定义的网格。除了列排序将列解释为字符串之外,它运行良好,而我希望将某些列排序为数值。

以下是我的网格定义。

我感兴趣的按数字顺序排序的列是“incident_count”。我已经尝试为列指定类型:“number”属性,但它不起作用。

<div id="PatrolRecords">
    <div data-filterable='{ "mode": "row" }'
         data-role='grid'
         data-sortable='true'
         data-detail-template='patrolDetailTemplate'
         data-detail-init='detailInit'
         data-bind='source: reportData.Patrols, events: {excelExport: excelExportHandler}'
         data-pageable='{ "pageSize": 10 }'
         data-toolbar='["excel"]'
         data-excel='{ "fileName": "Patrols.xlsx", "allPages": "true" }'
         data-columns='[
               {
                    field: "patrol_id_plain",
                    title: "Patrol ID",
                    filterable: false,
                    width: 70
                },
                {
                    field: "incident_count",
                    title: "Incidents",
                    filterable: false,
                    type: "number",     
                    width: 70
                },
                {
                    title: "GPS",
                    template: kendo.template($("#gpsTemplate").html()),
                    filterable: false,
                    width: 50
                },
                {
                    title: "",
                    template: kendo.template($("#viewLinkTemplate").html()),
                    filterable: false,
                    width: 60
                },
        ]'>
    </div>
</div>

这是我的viewmodel / datasource:

    viewModel = kendo.observable({
        reportData: 
            "Patrols": 
                [{
                    "patrol_id": "yO0crrEjeNvlrkc3H8otng%3d%3d",
                    "patrol_id_plain": "7383748",
                    "tour_name": "Airport Towers",
                    "location_name": "Airport Towers",
                    "client_company": "Scottsdale Auto Center",
                    "address": "18881 Von Karman",
                    "city": "Irvine",
                    "abbreviation": "CA",
                    "end_date": "10/31/2016 11:56:47 AM",
                    "end_date_seconds": "531237407",
                    "first_name": "James",
                    "last_name": "Wierzba",
                    "patrolled_by": "James Wierzba",
                    "incident_only": "0"
                },
                    "patrol_id": "KhZmgPq2fbSP3Zly%2bw2I5Q%3d%3d",
                    "patrol_id_plain": "7383747",
                    "tour_name": "Airport Towers",
                    "location_name": "Airport Towers",
                    "client_company": "Scottsdale Auto Center",
                    "address": "18881 Von Karman",
                    "city": "Irvine",
                    "abbreviation": "CA",
                    "end_date": "10/10/2016 6:24:01 AM",
                    "end_date_seconds": "529403041",
                    "first_name": "James",
                    "last_name": "Wierzba",
                    "patrolled_by": "James Wierzba",
                    "incident_only": "0"
                ],
        excelExportHandler: function (e) {
            var sheet = e.workbook.sheets[0];

            for (var i = 1; i < sheet.rows.length; i++) {
                var row = sheet.rows[i];
                var data = e.data.reportData.Patrols[i - 1];

                if (data.incident_only == "1") row.cells[6].value = '-';
                else row.cells[6].value = data.completed_checkpoint_count + ' of ' + data.total_checkpoint_count;


    }
    }
});

1 个答案:

答案 0 :(得分:0)

尝试在DataSource中指定数据类型,特别是在模型语句中。