剑道UI电网数据源过滤日期格式(kendo ui grid datasource filter da

2019-08-03 05:25发布

我有一个在数据源日期字段剑道网格。 在显示领域我使用模板在英国的日期格式来显示日期“DD / MM / YYYY”。 问题是过滤的时候,我不知道如何显示在英国的日期格式过滤器。

我有另外一个问题是,没有日期时间类型,只是日期,所以只能按日期不是日期时间进行筛选。

任何帮助或想法,将不胜感激。

这是局部视图(CSHTML)

<script type="text/javascript">
$(document).ready(function() {
    var date = new Date();
    var dateString = date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear();
    var url = '@Url.Action(AccountTypeController.GetAllocationGridData, new {id = Model.Id})';

    var dataSource = new kendo.data.DataSource({
        serverPaging: true,
        serverSorting: true,
        serverFiltering: true,
        pageSize: 10,
        transport: {
            read: {
                type: 'post',
                dataType: 'json',
                url: url
            },
            parameterMap: function(options) {
                if (options.filter) {
                    for (var i = 0; i < options.filter.filters.length; i++) {
                        if (options.filter.filters[i].field == 'Start' || options.filter.filters[i].field == 'End') {
                            options.filter.filters[i].value = kendo.toString(options.filter.filters[i].value, "MM/dd/yyyy");
                        }
                    }
                }
                return options;
            }
        },
        schema: {
            data: 'Data',
            total: 'Count',
            model: {
                id: 'Id',
                fields: {
                    Id: { type: 'number' },
                    Start: { type: 'date' },
                    End: { type: 'date' },
                    Allocation: { type: 'number' }
                }
            }
        },
        sort: {
            field: "Start",
            dir: "asc"
        },
        filter:{
            logic: "and",
            filters: [
                {
                    field: "End",
                    operator: "gt",
                    value: dateString
                }
            ]
        }
    });

    $('#account-allocation').kendoGrid({
        height: 383,
        dataSource: dataSource,
        columns: [
            {
                field: 'Start',
                title: 'Start Date',
                template: '#= kendo.toString(Start,"dd/MM/yyyy HH:mm") #'
            },
            {
                field: 'End',
                title: 'End Date',
                template: '#= kendo.toString(End,"dd/MM/yyyy HH:mm") #'
            },
            {
                field: 'NoSpaces',
                title: 'Number of Spaces',
                filterable: false
            },
            {
                field: 'Id',
                filterable: false,
                title: 'Actions',
                template: '<a class="link-lightbox" href="@Url.Action(AccountTypeController.UpdateAllocationAction1, AccountTypeController.Name)/#= Id #"><img src="@Url.Content("~/Content/img/grid-update.png")" alt="Update"/></a>',
                width: 75
            }
        ],
        filterable: true,
        sortable: false,
        scrollable: false,
        pageable: true          
    });
</script>

<div class="panel panel-w">
    <h2>@Model.Name Allocations
            <a href="@Url.Action(AccountTypeController.SetAllocationAction1, new { id = Model.Id })" class="button link-lightbox"><span class="edit">Set Account Type Allocation</span></a>
    </h2>
    <div id="account-allocation"></div>
</div>

Answer 1:

首先包括与英语文化的JavaScript文件:

<script src="http://cdn.kendostatic.com/2012.2.710/js/cultures/kendo.culture.en-GB.min.js"></script>

然后调用kendo.culture设置当前的文化:

kendo.culture("en-GB");

然后剑道电网将自动使用“DD / MM / YYYY”格式。

关于剑道UI如何与全球化交易的更多信息可以在中找到文件 。

这里有一个现场演示: http://jsbin.com/onetol/1/edit



文章来源: kendo ui grid datasource filter date format