简体   繁体   English

Kendo UI Jquery 匹配来自网格的数据源

[英]Kendo UI Jquery match Datasource from grid

I have a Kendo UI grid on my page which populates dataSource from an ajax call to my api in backend.我的页面上有一个 Kendo UI 网格,它从 ajax 调用到后端的 api 填充数据源。 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:我在名为 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"
                        }

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.编辑:我尝试将变量设置为网格的页面属性并在数据源中使用它,但它不起作用。

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 .您可以尝试通过pager 字段获取 Grid 的当前页面,提供对附加到 Grid 的 Pager 小部件及其page 方法的引用。

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

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