Array filter is returning data very slowly

南楼画角 提交于 2019-12-11 23:56:44

问题


I am using knockout arrayfilter to filter items. But if there are more than 1000 records then it returns data very slowly. What should i do for it? Here is my method

viewModel.filteredData = ko.computed(function () {
var str = "<temp>";
if (viewModel.selection() == "All") return viewModel.dataOne();
return ko.utils.arrayFilter(viewModel.dataOne(), function (data) {
    stringFromArray = data.display;
    if (stringFromArray.indexOf(str) == 0) {
        return true;
    }

   });
});

Here is my fiddle

When i select option button "All" then it will load all the data and if i select "Selected" then it will filter record. Right now i dont have much records in my fiddle so its filtering pretty fast. But in my real life application i have more than 5000 records and it takes 10 seconds to show All records. What i mean is i load data from my service and data is loaded and option button "All" is selected. Then i select "Selected" option button which filters record in 3-5 seconds. Now when i again click on "All" option button then it takes 10 seconds to reload data. How could i improve speed.

I also read about question here but was not able to understand it.

Update1

I have decided to do server side paging. Can someone give me links to do server side paging using kogrid? I am using WCF services to retrieve data. Do i need to pass pagesize parameter to service everytime when its called. Do let me know if there is any example using kogrid with wcf service.


回答1:


May be this link here will help you..

Iterating through a list of users and pushing to an array in knockout

This is how you would set up your viewmodel to enable paging.

And this link here

Make a WCF Service Accept JSON Data from jQuery.AJAX()

would help you get your WCF service work. Of course, the data would be the paging data from the first link.



来源:https://stackoverflow.com/questions/18186635/array-filter-is-returning-data-very-slowly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!