简体   繁体   English

分页不适用于KO Grid

[英]pagination not working for KO Grid

I am working with KO-grid and it seems to load all the data fine. 我正在使用KO-grid,它似乎可以加载所有数据。 Now, I am working on the pagination part and it does not seem to work properly. 现在,我正在研究分页部分,它似乎无法正常工作。 Yes, I do the pagination control on the bottom but when it comes to be able to decide the page size, it does not seem to work. 是的,我在底部进行分页控制,但是当它能够决定页面大小时,它似乎不起作用。 The page size is driven by two options according to confguration details given on https://github.com/ericmbarnard/KoGrid/wiki/Configuration 根据https://github.com/ericmbarnard/KoGrid/wiki/Configuration上提供的配置详细信息,页面大小由两个选项驱动

1.pageSizes:[5,10, 25] -- seems to show options but when I change my selection from 5 to 10 then it does nto seem to work upon the choices. 1.pageSizes:[5,10,25] - 似乎显示了选项,但是当我将我的选择从5更改为10时,它似乎无法选择。 2.pagesize ://somenumber -- breaks the code. 2.pagesize:// somenumber - 打破代码。

I have working model of it on jsfiddle: http://jsfiddle.net/sf4p3/46/ 我在jsfiddle上有它的工作模型: http//jsfiddle.net/sf4p3/46/

Any suggestions? 有什么建议么?

Well, it appears that the pagination in KoGrid doesn't work the magic that you were hoping for. 好吧,似乎KoGrid中的分页并不能达到您所希望的魔力。

Here's a link to the example from the KoGrid wiki on GitHub: 这是GitHub上KoGrid wiki示例的链接:

http://ericmbarnard.github.com/KoGrid/examples/Complex-Server-Side-Paging.html http://ericmbarnard.github.com/KoGrid/examples/Complex-Server-Side-Paging.html

In viewing source for the HTML page, one will likely see the beginning of the view model declaration without having to scroll (depending on screen resolution, of course). 在查看HTML页面的源代码时,可能会看到视图模型声明的开头而不必滚动(当然,取决于屏幕分辨率)。 Regardless, this starts around line 30. 无论如何,这都是从第30行开始的。

Notice that there is an observable named pageSize in the view model, and it is set to 50. 请注意,视图模型中有一个名为pageSize的可观察对象,它设置为50。

Scrolling down a bit, one should see functions named filter , sort , and getPagedDataAsync for filtering the data, sorting the data, and creating the data set for the current page. 向下滚动一下,应该看到名为filtersortgetPagedDataAsync函数,用于过滤数据,排序数据以及为当前页面创建数据集。

Here's the code for the getPagedDataAsync function: 这是getPagedDataAsync函数的代码:

this.getPagedDataAsync = function (pageSize, page, filterInfo, sortInfo) {
    setTimeout(function () {
        var data = window.getExampleData();
        var filteredData = filter(data(), filterInfo);
        var sortedData = sort(filteredData, sortInfo);
        var pagedData = sortedData.slice((page - 1) * pageSize, page * pageSize);
        self.myObsArray(pagedData);
    }, 0);
};

Without seeing the details of the rest of the view model, one should be able to tell from reading the above code that this function starts by retrieving all data to be displayed for this example page, then filters the data and sorts the data. 在没有看到视图模型的其余部分的细节的情况下,应该能够通过阅读上面的代码来判断该函数是通过检索要为该示例页面显示的所有数据而开始的,然后过滤数据并对数据进行排序。

After that, the data array is sliced to extract the data to be viewed for the current page, and that slice is passed to the myObsArray observable array that is used to display the data in the grid. 之后,切片数据数组以提取要为当前页面查看的数据,并将该切片传递给myObsArray可观察数组,该数组用于显示网格中的数据。

Here's the declaration of the grid in this example: 这是此示例中网格的声明:

<div id="sandBox" class="example" style="height: 600px; max-width: 700px;" 
    data-bind="koGrid: { 
        data: myObsArray,
        columnDefs: [ 
            { field: 'Sku', width: 140 },
            { field: 'Vendor', width: 100 },
            { field: 'SeasonCode', displayName: 'Season Code', width: 150 },
            { field: 'Mfg_Id', displayName: 'Mfg ID', width: 180 },
            { field: 'UPC', width: 170 }
        ],
        autogenerateColumns: false,
        isMultiSelect: false,
        enablePaging: true,
        useExternalFiltering: true,
        useExternalSorting: true,
        filterInfo: filterInfo,
        sortInfo: sortInfo,
        pageSize: pageSize,
        pageSizes: [25, 50, 75],
        currentPage: currentPage,
        totalServerItems: totalServerItems,
        selectedItem: selectedItem }">
</div>

Hopefully, this helps, and you'll be able to fix your paging issues. 希望这有帮助,您将能够解决您的分页问题。

Regardless, please let me know if you have any questions. 无论如何,如果您有任何疑问,请告诉我。

UPDATE UPDATE

@Californicated I'm on vacation, but I had some downtime to take a peek at your latest fiddle. @Californicated我正在度假,但我有一些停机时间来偷看你最近的小提琴。

I forked what you had in your latest fiddle and made the following changes to get the paging to work: 我在您最新的小提琴中分叉了您的内容,并进行了以下更改以使分页工作:

In the declaration of observables, I changed the value of pageSize to 2 and the value of totalServerItems to 7. In the JS, I changed the declaration of the data var in the getPagedDataAsync function so it's retrieving the Prizefillfilmentstatuses observable array. 在observables的声明中,我将pageSize的值更改为2,将totalServerItems的值totalServerItems为7.在JS中,我更改了getPagedDataAsync函数中data var的声明,因此它检索了Prizefillfilmentstatuses可观察数组。

On the last line of the JS code, I changed the first parameter from 50 to 2. In the jsFiddle toolbar, I changed the first dropdown from "onLoad" to "no wrap (body)" 在JS代码的最后一行,我将第一个参数从50更改为2.在jsFiddle工具栏中,我将第一个下拉列表从“onLoad”更改为“no wrap(body)”

In the declaration of the koGrid in the HTML, I added the following options/parameters: 在HTML中的koGrid声明中,我添加了以下选项/参数:

pageSize: pageSize,
currentPage: currentPage,
totalServerItems: totalServerItems,
selectedItem: selectedItem

The page setup was working with the JS changes, alone, but the paging tool (previous, next, etc.) was not active until I added the totalServerItems option in the koGrid declaration. 页面设置单独使用JS更改,但是在我在koGrid声明中添加了totalServerItems选项之前,分页工具(上一个,下一个等)没有激活。

Again, let me know if you have any questions. 如果您有任何问题,请再次告诉我。

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

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