Kendo UI Jquery 匹配网格中的数据源

发布于 2025-01-12 11:50:01 字数 5634 浏览 1 评论 0 原文

我的页面上有一个 Kendo UI 网格,它通过 ajax 调用填充后端 api 的数据源。 我在脚本标签中引入了另一个名为 dataSource 的变量,它从相同的 api 获取数据,并将在多个函数中使用,如下所示:

var dataSource = new kendo.data.DataSource
                    ({
                        type: "json",
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true,
                        allowUnsort: true,
                        pageSize: 10,
                        group:{field:"Status"},
                        transport: 
                        {
                            read: 
                            {
                                url: window.location.origin + "/api/HL7Message/getListOfProcessedData/",
                                dataType: "json",
                                type: "POST",
                                contentType: "application/json;",
                                cache: false,
                                async: false
                            },
                            parameterMap: function (options) 
                            {
                                return JSON.stringify(options);
                            }
                        },
                        serverSorting: true,                                    // server Side sorting by 
                        sort: { field: "ModifiedDate", dir: "desc" },           // Descending Modified Date
                        batch: true,
                        schema: 
                        {
                            model: 
                            {
                                id: "SampleId",
                                fields: 
                                {
                                    SampleId: { type: "string" },
                                    Status: { type: "string" },
                                    IsStored: { type: "string" },
                                    CreatedDate : { type:"date"},
                                    ModifiedDate:{type:"date"},
                                    ExceptionMsg: { type: "string" }
                                }
                            },
                            data: "data", total: "total"
                        }

我想通过获取当前网格中的页码并在页面中使用它来将此数据源同步到我的数据网格财产。

这是我的网格:

$("#grid").kendoGrid({
                    dataSource: dataSource,
                    height: 720,
                    pageable: {
                        refresh: true,
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true,
                    },
                    sortable: true,
                    filterable: false,
                    scrollable: false,
                    navigatable: false,
                    noRecords: true,
                    dataBound: onDataBound,
                    toolbar: [
                        "Queue Data Status",
                        { template: "<button id='RegenerateButton' onclick=regenerateAll()>Regenerate All</button>"} ,
                        "search"],
                    columns: [{
                        field: "sampleId",
                        title: "Sample Id",
                        template: "<div class='msg-photo' style='background-image: url(/images/email_material.png);background-size: cover;background-size: 70px 70px'></div><div class='sample-id'>#: sampleId #</div>",
                        width: 150
                    },{
                        field: "createdDate",
                        title: "Created Date",
                        template:"<div class='createdDateTemplate'>#= kendo.toString(kendo.parseDate(createdDate), 'dd/MM/yyyy hh:mm tt') #</div>",
                        width: 150
                    },{
                        field: "modifiedDate",
                        title: "Modified Date",
                        template:"<div class='modifiedDateTemplate'>#= kendo.toString(kendo.parseDate(modifiedDate), 'dd/MM/yyyy hh:mm tt') #</div>",
                        width: 150
                    },{
                        field: "isStored",
                        title: "Data Stored In Blob",
                        template: "<span id='badge_#=sampleId#' class='isStoredBadgeTemplate'></span>",
                        width: 150
                    }, {
                        field: "status",
                        title: "Status Of Data",
                        template: "<span id='badge_#=sampleId#' class='statusBadgeTemplate'></span>",
                        width: 150
                    },{
                        field: "exceptionMsg",
                        title: "Exception Message",
                        width: 150,
                        sortable: false,
                        template: "#if(status=='F'){#<div id=badge_#=sampleId# class=exceptionBadgeTemplate>#=exceptionMsg#</div>#} else {##}#",
                    },{
                        field: "Retry",
                        title: "Action",
                        width: 100,
                        sortable: false,
                        template: "#if(status=='F'){#<button class=btn btn-info onclick=regenerateFile(#=sampleId#)>Regenerate</button>#} else {#<button class=btn btn-info disabled>Regenerate</button>#}#"
                    }],
                });
            });

我应该怎么做?

或者有更好的方法吗? 编辑:我尝试将变量设置为网格的页面属性并在数据源中使用它,但它不起作用。

I have a Kendo UI grid on my page which populates dataSource from an ajax call to my api in backend.
I have introduced another variable in script tag called dataSource which gets the data from same api and will be used in multiple functions like this:

var dataSource = new kendo.data.DataSource
                    ({
                        type: "json",
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true,
                        allowUnsort: true,
                        pageSize: 10,
                        group:{field:"Status"},
                        transport: 
                        {
                            read: 
                            {
                                url: window.location.origin + "/api/HL7Message/getListOfProcessedData/",
                                dataType: "json",
                                type: "POST",
                                contentType: "application/json;",
                                cache: false,
                                async: false
                            },
                            parameterMap: function (options) 
                            {
                                return JSON.stringify(options);
                            }
                        },
                        serverSorting: true,                                    // server Side sorting by 
                        sort: { field: "ModifiedDate", dir: "desc" },           // Descending Modified Date
                        batch: true,
                        schema: 
                        {
                            model: 
                            {
                                id: "SampleId",
                                fields: 
                                {
                                    SampleId: { type: "string" },
                                    Status: { type: "string" },
                                    IsStored: { type: "string" },
                                    CreatedDate : { type:"date"},
                                    ModifiedDate:{type:"date"},
                                    ExceptionMsg: { type: "string" }
                                }
                            },
                            data: "data", total: "total"
                        }

I want to sync this datasource to my data grid by getting the page number currently in grid and using it in page property.

This is my Grid:

$("#grid").kendoGrid({
                    dataSource: dataSource,
                    height: 720,
                    pageable: {
                        refresh: true,
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true,
                    },
                    sortable: true,
                    filterable: false,
                    scrollable: false,
                    navigatable: false,
                    noRecords: true,
                    dataBound: onDataBound,
                    toolbar: [
                        "Queue Data Status",
                        { template: "<button id='RegenerateButton' onclick=regenerateAll()>Regenerate All</button>"} ,
                        "search"],
                    columns: [{
                        field: "sampleId",
                        title: "Sample Id",
                        template: "<div class='msg-photo' style='background-image: url(/images/email_material.png);background-size: cover;background-size: 70px 70px'></div><div class='sample-id'>#: sampleId #</div>",
                        width: 150
                    },{
                        field: "createdDate",
                        title: "Created Date",
                        template:"<div class='createdDateTemplate'>#= kendo.toString(kendo.parseDate(createdDate), 'dd/MM/yyyy hh:mm tt') #</div>",
                        width: 150
                    },{
                        field: "modifiedDate",
                        title: "Modified Date",
                        template:"<div class='modifiedDateTemplate'>#= kendo.toString(kendo.parseDate(modifiedDate), 'dd/MM/yyyy hh:mm tt') #</div>",
                        width: 150
                    },{
                        field: "isStored",
                        title: "Data Stored In Blob",
                        template: "<span id='badge_#=sampleId#' class='isStoredBadgeTemplate'></span>",
                        width: 150
                    }, {
                        field: "status",
                        title: "Status Of Data",
                        template: "<span id='badge_#=sampleId#' class='statusBadgeTemplate'></span>",
                        width: 150
                    },{
                        field: "exceptionMsg",
                        title: "Exception Message",
                        width: 150,
                        sortable: false,
                        template: "#if(status=='F'){#<div id=badge_#=sampleId# class=exceptionBadgeTemplate>#=exceptionMsg#</div>#} else {##}#",
                    },{
                        field: "Retry",
                        title: "Action",
                        width: 100,
                        sortable: false,
                        template: "#if(status=='F'){#<button class=btn btn-info onclick=regenerateFile(#=sampleId#)>Regenerate</button>#} else {#<button class=btn btn-info disabled>Regenerate</button>#}#"
                    }],
                });
            });

How should I do so?

Or is there some better approach ?
Edit: I have tried setting a variable to page property of grid and using it in datasource but it isnt working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多像笑话 2025-01-19 11:50:01

您可以尝试通过 获取网格的当前页面寻呼机字段,提供对附加到网格的寻呼机小部件的引用,它是 页面方法

You can try getting the current page of the Grid via the pager field, providing reference to the Pager widget attached to the Grid, and it's page method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文