ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
How to show summary data for the whole grid?
Title:
B
I
{code}
?
I have a grid with search results. The results show items with monetary value, and I'd like to show the total monetary value of all the search results. The search results might have 1000 items, of which 1-10 are on the first page of the grid. At the top of the grid, I'd like to show the total value of all 1,000 items. What do you recommend?
Save Changes
Cancel
David Austin
asked at 02 Feb 2016
do you want to show the summary outside the grid (above) or in the grid footer like in the grouping demo ? (it can be done both ways)
at 02 Feb 2016
Omu
Outside the grid would be cleaner in my case. Also, preferably get the summary numbers in a separate call to the controller.
at 02 Feb 2016
David Austin
Answers
B
I
{code}
?
the grid model has an object Tag parameter used to send additional info on grid load so you can do something like this: var gridModel = new GridModelBuilder<Lunch>(Db.Lunches.AsQueryable(), g).Build(); gridModel.Tag = new { MyParam = "hi", SummaryStr = "...", ParamUsedToLoadSummary = ...}; return Json(gridModel); so you can choose to send the rendered summary, or numbers, or other values that will be used to make an additional request and in the view you bind to 'aweload' $('#MyGrid').on('aweload', function(e, res){ alert(JSON.stringify(res.Tag); });
Save Changes
Cancel
Omu
answered at 02 Feb 2016
I see this is somewhat duplicate to this forum question: http://aspnetawesome.com/forum/question/507/add-total-count-to-the-grid.
at 02 Feb 2016
David Austin
The code below only returns thesum for the items on the current page. How might I get the sum for all the items in the result set? I used: { Key = "item_id", Map = MapToGridModel, PageCount = pageCount, ItemsCount = itemCount }.Build(); gridModel.Tag = new { ItemsValue = items.Sum(o => o.price_ext) };
at 02 Feb 2016
David Austin
GridModelBuilder has sorted and paged the 'items'; calculate ItemsValue before you pass items to GridModelBuilder, of course this will pull all your 1000 items from the Db, maybe you could instead run a sql query that will give you the avg value you need
at 02 Feb 2016
Omu
Ok, got it. I applied custom paging before calculating the sum. Fixed it.
at 02 Feb 2016
David Austin
How do you suggest doing this separately from the grid control? I have a Html.Awe().TextBox to enter the key word to search and a Html.Awe().MultiLookup passing an array of integers. Both awe controls are parents to the grid. This part works. I'd like to add the summary info as a separate call to a MVC controller after the grid has updated. Reason is because the summary info takes a long time to calculate, so I'd like to show the user grid results really fast and then follow up with the summary info. The summary info controller would also need to accept the key word search as a parent.
at 02 Feb 2016
David Austin
it's probably slow because you're pulling all the records and after calculating the sum, would be faster to execute a sql query that calculates the sum; to do the request just call an $.ajax with the needed parameters after fill the div $('#summary').html(result)
at 02 Feb 2016
Omu
Ok, I created it using the $.ajax method. Now I'd like to call the function to update the summary after the grid loads. I tried {$('#SearchItemGrid').on('aweload', UpdateGridSummary());} but it runs as soon as the grid loads, not after the data has returned. Can I call the UpdateGridSummary() method after the grid receives its data?
at 02 Feb 2016
David Austin
you're not supposed to use .on(event, func()) instead use .on(event, func) unless func() returns a Function
at 02 Feb 2016
Omu
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK