Binding MVC grid to stored procedure with large amount of data - model-view-controller

Binding MVC grid to stored procedure with large amount of data:
I want to bind MVC grid to an object result that returned from SP
Normally the grid request only data needed to be shown to the user and that will be very good when binding to a table with large amount of data that lets the grid fast and its performance would be good.
i have 2 ways to bind MVC grid with SP:
Bind to SP without using .ToList() it gives me an error "The result of a query can not be enumerated more than once."
Bind to sp using .ToList() will resolve that error but it will loads all records from database first and the performance will be bad and the grid loading, paging, sorting and filtering would be very slow.
Please tell me a solution to bind MVC grid with SP that returns large amount of data with good performance.
Thank you

I have used jqgrid in the past, jqgrid implements paging so not all the content of the grid is actually displayed at once, you pick the number of rows per page and jqgrid automatically will hook the navigation to your controller. There are a lot of examples of this on the web. If you click the next page it will retrieve the appropriate data for that page and so forth.
The jqgrid page has a lot of examples in loading data that ilustrate this: http://www.trirand.com/blog/jqgrid/jqgrid.html, here is another page that talks how that is implemented at the server side using mvc http://www.codersource.net/AspNet/ASPNetAdvanced/jqGridPaginginaspnetmvc.aspx, I'm sure if you look around you'll find a lot of information on how to go about this approach.
Finally I usually avoid showing the user a lot of data anyways, mainly because it is hard for a human been to make any sense of more than 100 rows of data having a way to search further in it. So I rather try and attempt to shrink the data size giving them a way to filter it down further, but this is not always possible.
Hope this helps.

Related

How Pagination works internally in JQ grid?

Is JQgrid create all records in DOM or store locally in JavaScript object show records on pagination event?
Thanks
We tried JQ grid in our project experience slowness rendering table for large number of records (10,000) with page size of 50.
jqGrid stores the local data in array and display in DOM only the portion set in rowNum parameter.
Personally I think that loading 10k records locally is to big for any grid component. This will consume a lot of memory and will slow dawn any operation in the application.
The best is to store the data on server and request only the portion you want. Look here how we deal with 1 million records

KendoUi Grid page size performance issue

I am using kendoUi Grid with 20k records, When i am changing page size 20 to 200 grid taking 40 to 50 sec to work. some times it taking min. paging is client side only.
For large datasets, it's better to use server paging, mainly because:
Faster loads
Avoid wasting memory
Avoid unnecessary database and network loads, database just gives you the number of records of the current page
You should consider enabling server paging at datasource level, and then read pagination values on backend side before performing the query to the database.
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-serverPaging
good question, i am also faced this type of issue.
Please use MVVM logic instance of MVC for bind the grid,
for more please find this below link.
http://demos.telerik.com/kendo-ui/grid/mvvm

DataTables Editor: possible to use AjAX calls for retrieving data?

I noticed that in all the examples provided by the website, all data is retrieved from the database at page load. However, in my case this would result in having to retrieve a significant amount of data, from which only part of it is being edited. I am no expert, but this would seem inefficient in terms of performance. I've also seen PhpGrid.org and they seem to use AJAX calls for each page.
Would you agree, or could someone explain why the current method is in fact more efficient?
Is there a way to only retrieve data for the page that is being viewed (i.e. via AJAX calls) ?
Can someone convince me? :-)
Please refer to DataTables manual page about data for more information. Below is an excerpt:
DataTables has two different modes of processing data (ordering,
searching, etc. of data):
Client-side processing - the full data set is loaded up-front and data processing is done in the browser.
Server-side processing - an Ajax request is made for every table redraw, with only the data required for each display returned. The
data processing is performed on the server.
Each has its own advantages and disadvantages, but the key indicator
for which mode you should select is based on the number of rows in
your table.
You're referring to client-side processing mode which loads all data at once. However, in server-side processing mode only current page data is loaded which improves performance.

Grid - When should you switch from html to server side table processing?

,This question is likely subjective, but a lot of "grid" Javascript plugins have come out to help paginate and sort tables. They usually work in 2 ways, the first and simplest is that it takes an existing HTML <table> and converts it into a sortable and searchable information. The second is that it passes info to the server and has the server select info from the database to be displayed.
My question is this: At what point (size wise) is it more efficient to use server-side processing vs displaying all the data and have the "grid plugin" convert it to a sortable/searchable table client-side?
Using datatables as an example, I have to execute at least 3 queries to get total rows in the table, total filtered results for pagination, and the filtered results to be displayed for the specific selected page. Then every time I sort, I am querying again. Every time I move to another page, or search in the table, more queries.
If I was to pull the data once when the client visits the page, I would be executing a single query, and then formatting and pushing the results to the client all at once. This increases the page size, and possibly delays loading of the page once it gets too big. The upside is there will only one query, and all the sorting, searching, and pagination is handled by the plugin, so no waiting for a response and no more queries.
If I was to have just a few rows, I imagine just pushing the formatted table data to the client at the page load would be the fastest. But with thousands of rows, switching to server-side would be the most efficient way.
Where is the tipping point? Is there a tipping point, or is server-side or client-side the way to go 100% of the time?
The answer on your question can be only subjective. So I explain how I personally understand the problem and give me recommendation.
In my opinion the data with 2-3 row and 3-4 column can be displayed in HTML table without usage any plugin. The data you display for the user the more important will be that the user will be able to grasp the information which will be displayed. So I think that the information for example have to be good formatted and marked with colors and icons for example. This with help to grasp information from probably 10 rows of data, but not much more. If you just display table with 100 rows or more then you overtax the user. The user will have to analyse the data to get any helpful information from the table. Scrolling of the data makes this not easier.
So I think that one should give the user comfortable or at least convenient interface to sort and to filter the data from the table. The exact interface is mostly the matter of taste. For example the grid can have an additional filter bar
For filtering and even for sorting of the data it's important to have not pure strings, but to be able to distinguish the data types like integer (10 should be after 9 and not between 1 and 2), numbers (correct interpret '.' and ',' inside of numbers), dates (3/20/2012 should be grater as 4/15/2010) and so on. If you just convert HTML table to some grid you will have problems with correct filtering or sorting. Even if you use pure local JavaScript data to display in grid it would be important to have datasource which has some kind of type information and then to create the grid based in the data. In the case you can gives date as JavaScript Date or as ISO 8601 string "2012-03-20" and in the grid display the data corresponds the specified formatter as 3/20/2012 or 20-Mar-2012.
Whether you implement filtering, sorting and paging on the server side or on the client side is not really important for the user who open the page. It's important only that all works quickly enough. The exact choose of the grid plugin, the filtering (with filter toolbar or external controls) and styling of the grid depend on your taste and the project requirements.

Telerik MVC grid paging bringing back a certain number of records at a time

I am using the latest version of Telerik MVC extensions, ASP.NET MVC 3 with the Razor view engine. I am using entiry framework 4.1 code first with no stored procedures.
I worked through the example at http://demos.telerik.com/aspnet-mvc/grid/paging and I'm not sure if this is what I am looking for.
I am trying to implement paging. The amount of rows on my grid is 50. When the grid loads for the first time it must do a database table call and fetch the first 50 records. When you go to the next 50 rows, then it must return the next set of 50 records.
The sample ueses view data, I'm not comfortable using view data. It's not safe? Isn't there a decent example to be used on the net?
Also, if I have loaded the first 50 records, and I go to the next page, is there a way of caching the previous records so that it is there?
Implementing a caching solution for Entity framework is completely your own choice, it is definitely possible although I'm becoming less convinced of the value in doing this.
You don't need to use ViewData to provide data to the Telerik grid and one of the huge bonuses of using their grid is that if you have an IQueryable<T> data source it will automagically provide paging, sorting, filtering functionality straight out of the box.
You didn't state if you are using server or client binding, so i haven't attempted to write any code.
Sounds like you might be using server-side binding though.

Resources