繁体   English   中英

根据第二个数据源更改剑道网格的值

[英]Change Value of kendo grid based on second datasource

我对kendo和javascript都很陌生,因此请原谅知识的任何失误。 我有一个Kendo网格,其中的字段名为TicketStatusID。 我还有另一个具有TicketStatusID和TicketStatusName的独立数据源。 有没有一种方法可以用其他数据源中的TicketStatusName替换网格中的TicketStatusID?

这是我的网格:

var commentsDatasource = new kendo.data.DataSource({
        type: "odata",
        transport: {
            read: {
                //url: sBaseUrl,
                url: baseUrl + "TicketIssueComment",
                type: "get",
                dataType: "json",
                contentType: "application/json"
            },
            create: {
                url: baseUrl + "TicketIssueComment",
                type: "post",
                dataType: "json",
                ContentType: 'application/json',
                success: refresh
            },
        },

        schema: {
            data: "value",
            total: function (data) {
                return data['odata.count'];
            },
            model: {
                id: "TicketCommentID",
                fields: {
                    TicketCommentID: { type: "number" },
                    TicketID: { type: "number" },
                    TicketCommentValue: { type: "string" },
                    TicketCommentCreatedBy: { type: "string", defaultValue: "z13tas", editable: false },
                    TicketCommentCreatedTS: { type: "date", editable: false },
                    TicketStatusID: { type: "number", editable: false },
                    //TicketStatusName: { type: "string", editable: false }
                }
            }
        },
        filter: { field: "TicketID", operator: "eq", value: filterValue },

        pageSize: 50,
        serverPaging: true,
        serverFilering: true,
        serverSorting: true,
        sort: { field: "TicketID", dir: "asc" },
    });



    //-----------------KENDO GRID-----------------
    $("#gridComments").kendoGrid({
        dataSource: commentsDatasource,
        pageable:
            {
                refresh: true,
                pageSizes: [10, 25, 50, 100],
                buttonCount: 5
            },
        //height: 300,
        width: 300,
        //sortable: true,
        toolbar: ["create", "save", "cancel"],
        scrollable: true,
        reorderable: true,
        editable: true,
        selectable: "row",
        resizable: true,
        edit: function edit(e) {
            if (e.model.isNew() == false) {
                $('input[name=TicketCommentValue]').parent().html(e.model.TicketCommentValue);
            }
        },
        columns: [ 
            { field: "TicketCommentValue", title: "Comment", width: "500px" },
            { field: "TicketStatusID", title: "Status", width: "100px" }, 
            { field: "TicketCommentCreatedBy", title: "Created By", width: "100px" },
            { field: "TicketCommentCreatedTS", title: "Created Date", width: "150px", format: "{0:MM-dd-yyyy hh:mm tt}" }
        ]
    });

这是我的第二个数据源:

var StatusDatasource = new kendo.data.DataSource({
    type: "odata",
    transport: {
        read: {
            dataType: "json",
            url: baseUrl + "TicketIssueStatusView",
        }
    },
    schema: {
        data: "value",
        total: function (data) {
            return data['odata.count'];
        },
        model: {
            id: "TicketStatusID",
            fields: {
                TicketStatusID: { type: "number" },
                TicketStatusName: { type: "string" },
                TicketStatusDescription: { type: "string" },
                TicketStatusUpdatedTS: { type: "date" },
                TicketStatusUpdatedBy: { type: "string" },
            }
        }
    },
    serverFilering: true,
    optionLabel: "--Select Value--"
});

我想我可能会到一些与该解决方案在这里- http://demos.telerik.com/kendo-ui/grid/editing-custom -但Telerik的文档不提供如何实现的解释。 谢谢

从本示例中进行操作。

将此字段添加到要更改剑道网格的位置。

$.ajax({
            cache: false,
            type: "POST",
            url: "@Html.Raw(Url.Action("assing", "Customer"))",
            data: postData,
            complete: function (data) {
                //reload antoher grid
                var grid = $('#Customer-grid').data('kendoGrid');
                grid.dataSource.read();
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(thrownError);
            },
            traditional: true
        });

从下面的代码中,您的问题正在解决..请先尝试。

 var grid = $('#Customer-grid').data('kendoGrid');
 grid.dataSource.read();
{ 
    field: "TicketStatusID",
    title: "Status", 
    width: "100px",
    template: #= StatusDatasource.get(data.TicketStatusID).TicketStatusName #
}

请记住,您的StatusDatasource应该是顶级的,我的意思是可以作为windows.StatusDatasource ,并且在网格初始化之前已初始化和读取了数据(没有第一个条件就会出现错误,没有第二个条件您会在列内看到undefined )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM