I'm using Data Table as data source for IgGrid. When I'm trying to do remote sorting I'm getting error
ArgumentNullException: Value cannot be null.
System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property) +6153565 Infragistics.Web.Mvc.SortingExtensions.ApplyOrder(IQueryable source, String property, String methodName)
I'm converting data table into IQueryable<Object> like this
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row = null; foreach (DataRow dr in dataTable.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in dataTable.Columns) row.Add(col.ColumnName, dr[col] == DBNull.Value ? string.Empty : dr[col]); rows.Add(row); } return rows.AsQueryable<object>();
Here I cannot map my datatable into any specific model because datatable columns are getting change with input request.
Please suggest anyway to do remote sorting with data table as data source without creating any static model class.
Thanks!
Manish
Hi Manish,
I'm not sure why this exception is thrown. Can you please share your code for creating the grid? What model are you passing to the grid? Any other related information could be of help. Thank you.
JS code looks like
(function () {$('#igGridID').igGrid({ dataSource: '/App/screen/GridDataSourceBind?frmId=2723,
features: [ { filterExprUrlKey: 'filter', filterLogicUrlKey: 'filterLogic', name: 'Filtering', type: 'local', caseSensitive: false },{ sortUrlKey: 'sort', sortUrlKeyAscValue: 'asc', sortUrlKeyDescValue: 'desc', name: 'Sorting', type: 'remote', mode: 'multiple'},.....
MVC action for data Source looks like this
[GridDataSourceAction]
public ActionResult GridDataSourceBind(int frmId)
{
DataTable dataTable = //fetch it from BL logic
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row = null; foreach (DataRow dr in dataTable.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in dataTable.Columns) row.Add(col.ColumnName, dr[col] == DBNull.Value ? string.Empty : dr[col]); rows.Add(row); } return View(rows.AsQueryable<object>());
}
Manish:
Another approach you, or anyone else encountering this type of issue, might consider is to return anonymous objects from your LINQ query. This ensures that you're not stuck with a static type as the result of your controller action.
There are a few ways to accomplish this when your existing data layer returns DataTables/DataSets. I have in the past updated my repositories to have parallel methods - one that returns data as DataTables and another which returns enumerables or lists. The method that returns enumerables or lists is simply a wrapper method that calls the method which provides DataTables and then formats the data into collection-based types.
I hope this helps.
Best,
Craig
As workaround in MVC action we serialized the data table as JSON and deserialized by model
-Manish
Hello,
I'm following up to see if you still need assistance with the matter.
Please have a look at this sample, demonstrating how to use sorting and bind the grid to DataTable: http://www.igniteui.com/grid/sorting-remote
Can you tell me where exactly you are getting the exception you mentioned? If you can attach a small running sample, it would be very helpful, too.
Still getting same issue with dataSourceUrl.
MVC action is like
[GridDataSourceAction] [ActionName("datatable-binding")] public ActionResult BasicMvcHelper() { DataTable customers = GetCustomerDataTable(); return View(customers ); }
cshtml looks like this
@(Html.Infragistics().Grid<System.Data.DataTable>() .ID("grid1") .Height("400px") .Width("100%").AutoGenerateColumns(true)
.DefaultColumnWidth("150px")
.Features(features => { features.Sorting().Type(OpType.Remote); features.Paging().Type(OpType.Remote); features.Filtering().Type(OpType.Remote); }) .DataSourceUrl(Url.Action("datatable-binding")) .Render();