So I'm using Datatable.net, Asp.net MVC Controller serving up Json data.
I'm trying to do something simliar to these posts:
I have the following parameters from the Javascript Ajax call to the sever:
> int iSortingCols Number of columns to sort on > int iSortCol_(int) Column being sorted on > (you will need to decode this number for your database) > string sSortDir_(int) Direction to be sorted - "desc" or "asc".
Here's my Dataset:
var db = new GER_MAPV_Context();
var allTags = db.TrimTables;
filteredTags = db.TrimTables.AsEnumerable();
IEnumerable<TrimTable> filteredTags;
//Dependent function for Sorting
Func<TrimTable, string> getColumnName = (
c => getCurrentSortColumn(1) == 1 ? c.TAG :
sortColumnIndex == 2 ? c.DESCRIPTION :
sortColumnIndex == 3 ? c.SET_POINT :
sortColumnIndex == 4 ? c.PRIORITY :
sortColumnIndex == 5 ? c.LIMIT_TYPE :
sortColumnIndex == 6 ? c.ALARM_TYPE :
sortColumnIndex == 7 ? c.AUTOMATED_SYSTEM :
sortColumnIndex == 8 ? c.COL_POL :
sortColumnIndex == 9 ? c.PROPERTY :
sortColumnIndex == 10 ? c.EQUIP_TYPE:
sortColumnIndex == 11 ? c.P_ID :
sortColumnIndex == 12 ? c.AREA :
sortColumnIndex == 13 ? c.COMPLEX :
sortColumnIndex == 14 ? c.UNIT : //PI Unit Format Long-text
sortColumnIndex == 15 ? c.UNIT_ : //Loop Number Format
sortColumnIndex == 16 ? c.LOOP_TYPE : //Loop Type i.e. PI, FIT, PSV
sortColumnIndex == 17 ? c.LOOP_ : //Loop Number
sortColumnIndex == 18 ? c.LOOP_EXT :
c.UNIT
);
Then I need to Sort each of these columns accordingly up to 4 sorts.
filteredTags.OrderBy(getColumnName).ThenByDescending(getColumnName);
//could have 1 - 4 orderby.thenby arrangements
the trick is I need to input "sortColumnIndex"
(which is a number, and JSON parameter of iSortCol_1 or iSortCol_2 respectively)
into the getColumnName Function so it return the proper column name.
I'm racking my brain here.
Q: So what are the basic steps to do this?
And what is the basic jist of the LINQ expression I'm trying to build here?