0

I have 10 lakhs records in my database and I don't want to fetch all the data to display in UI client, so I implement paging using .skip() & .take() this works fine. But problem is when a user tries to sort the grid on a particular column how to dynamically sort & modify the query on the sorted column ?? (Note : I am using enitytframework to fetch data).

Thanks in Advance.

Abhinay
  • 338
  • 1
  • 7
  • 22

1 Answers1

0

Add links to the column headers in your grid that post back to the same form / view with a parameter that specifies the sort order. Execute your EF query again with an .OrderBy() that specifies the relevant column, apply any Where() clauses that were in effect when the user clicked the column header, and set the page back to #1.

Paul Taylor
  • 5,651
  • 5
  • 44
  • 68
  • How to dynamically change the column name in .OrderBy() ?? say default sort order is on column x (.OrderBy(x)) now if the sort order is changed from UI, how to dynamically change the column in sort order in EF ?? – Abhinay Dec 06 '12 at 09:50
  • 1
    To construct Lambda expressions dynamically, explore the System.Linq.Expressions namespace. Here are some ideas: http://stackoverflow.com/questions/307512/how-do-i-apply-orderby-on-an-iqueryable-using-a-string-column-name-within-a-gene. Alternatively, just write a switch statement and give a different query in each branch. – Paul Taylor Dec 06 '12 at 10:29