private void ReadSortConfiguration(ref IFilterRequest message, string key, object value) { Match match = Regex.Match(key, @"order\[([0-9]+)\](.+)"); if (match.Success && match.Groups.Count == 3) { int index = Convert.ToInt32(match.Groups[1].Value); string propertyName = match.Groups[2].Value; while (index >= message.Sort.Count) { message.Sort.Add(new Sort()); } if (propertyName == "[column]") { message.Sort[index].Column = GetValue <int>(value); } else if (propertyName == "[dir]") { message.Sort[index].Direction = GetValue <string>(value).AsSortDirection(); } } }
private void ReadColumnConfiguration(ref IFilterRequest message, JProperty property) { int separatorIndex = property.Name.LastIndexOf("_"); int index = Convert.ToInt32(property.Name.Substring(separatorIndex + 1)); string propertyName = property.Name.Substring(0, separatorIndex); IColumn currentColumn = null; if (!message.HasColumn(index)) { currentColumn = new Column(); message.Columns.Add(index, currentColumn); } else currentColumn = message.GetColumn(index); if (propertyName == "mDataProp") currentColumn.Data = property.Value.ToObject<string>(); else if (propertyName == "bSearchable") currentColumn.Searchable = property.Value.ToObject<bool>(); else if (propertyName == "bSortable") currentColumn.Sortable = property.Value.ToObject<bool>(); else if (propertyName == "sSearch") currentColumn.Search.Value = property.Value.ToObject<string>(); else if (propertyName == "bRegex") currentColumn.Search.IsRegex = property.Value.ToObject<bool>(); }
public PlainDataTableResult(IQueryable <TSource> query, IFilterRequest request, OutputType?outputType = null) : base(outputType) { IDataTableFilterProcessor filterProcessor = new DataTableFilterProcessor(); IDataTableProcessor processor = new DataTableProcessor(filterProcessor); this.Data = processor.Process(query, request); }
public static DataTableResult CreatePlain(IQueryable query, IFilterRequest request, OutputType?outputType = null) { var s = "CreatePlain"; var openCreateMethod = typeof(DataTableResultFactory).GetMethods().Single(x => x.Name == s && x.GetGenericArguments().Count() == 1); var queryableType = query.GetType().GetGenericArguments()[0]; var closedCreateMethod = openCreateMethod.MakeGenericMethod(queryableType); return((DataTableResult)closedCreateMethod.Invoke(null, new object[] { query, request, outputType })); }
public MutableDataTableResult(IQueryable <object> query, IFilterRequest request, OutputType?outputType = null) : base(outputType) { IDataTableFilterProcessor filterProcessor = new DataTableFilterProcessor(); IDataTableProcessor processor = new DataTableProcessor(filterProcessor); IPageResponse <object> response = processor.Process(query, request); this.Data = response; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jsonObject = JObject.Load(reader); IEnumerable <JProperty> properties = jsonObject.Properties(); Dictionary <string, JProperty> otherProperties = new Dictionary <string, JProperty>(); IFilterRequest message = Activator.CreateInstance(objectType) as IFilterRequest; foreach (JProperty property in properties) { if (property.Name == "draw") { message.Draw = property.Value.ToObject <int>(); } else if (property.Name == "start") { message.Start = property.Value.ToObject <int>(); } else if (property.Name == "length") { message.Length = property.Value.ToObject <int>(); } else if (property.Name == "search[value]") { message.Search.Value = property.Value.ToObject <string>(); } else if (property.Name == "search[regex]") { message.Search.IsRegex = property.Value.ToObject <bool>(); } else if (property.Name.StartsWith("order")) { ReadSortConfiguration(ref message, property); } else if (property.Name.StartsWith("columns")) { ReadColumnConfiguration(ref message, property); } else { otherProperties.Add(property.Name, property); } } JsonConvertHelper.ReadJson(message, otherProperties, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); return(message); }
/// <summary> /// Filters an IQueryable by one or more fields. /// </summary> /// <typeparam name="T">The collection type.</typeparam> /// <param name="source">The collection to be filtered.</param> /// <param name="request">An IFilterRequest with one or more Filter objects by which to filter the collection.</param> /// <returns>the IQueryable, filtered to include only items which match the specified filter(s).</returns> public static IQueryable <T> Filter <T>(this IQueryable <T> source, IFilterRequest request) { if (request != null && request.Filters != null && request.Filters.Any()) { var expression = FilterExpressionBuilder.GetFilterExpression <T>(request.Logic, request.Filters); return(source.Where(expression)); } return(source); }
private void ReadColumnConfiguration(ref IFilterRequest message, string key, object value) { Match match = Regex.Match(key, @"columns\[([0-9]+)\](.+)"); if (match.Success && match.Groups.Count == 3) { int index = Convert.ToInt32(match.Groups[1].Value); string propertyName = match.Groups[2].Value; IColumn currentColumn; if (!message.HasColumn(index)) { currentColumn = new Column(); message.Columns.Add(index, currentColumn); } else { currentColumn = message.GetColumn(index); } if (propertyName == "[data]") { currentColumn.Data = GetValue <string>(value); } else if (propertyName == "[name]") { currentColumn.Name = GetValue <string>(value); } else if (propertyName == "[searchable]") { currentColumn.Searchable = GetValue <bool>(value); } else if (propertyName == "[orderable]") { currentColumn.Sortable = GetValue <bool>(value); } else if (propertyName == "[search][value]") { currentColumn.Search.Value = GetValue <string>(value); } else if (propertyName == "[search][regex]") { currentColumn.Search.IsRegex = GetValue <bool>(value); } } }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (bindingContext == null) { throw new ArgumentNullException("bindingContext"); } IFilterRequest message = Activator.CreateInstance(_concreteType) as IFilterRequest; ReadConfiguration(ref message, StripPrefix(bindingContext, controllerContext.HttpContext.Request.QueryString)); ReadConfiguration(ref message, StripPrefix(bindingContext, controllerContext.HttpContext.Request.Form)); return(message); }
private void ReadConfiguration(ref IFilterRequest message, NameValueCollection collection) { Dictionary <string, object> otherValues = new Dictionary <string, object>(); foreach (string key in collection.AllKeys) { if (key == "draw") { message.Draw = GetValue <int>(collection[key]); } else if (key == "start") { message.Start = GetValue <int>(collection[key]); } else if (key == "length") { message.Length = GetValue <int>(collection[key]); } else if (key == "search[value]") { message.Search.Value = GetValue <string>(collection[key]); } else if (key == "search[regex]") { message.Search.IsRegex = GetValue <bool>(collection[key]); } else if (key.StartsWith("order")) { ReadSortConfiguration(ref message, key, collection[key]); } else if (key.StartsWith("columns")) { ReadColumnConfiguration(ref message, key, collection[key]); } else { otherValues.Add(key, collection[key]); } } FormConvertHelper.ReadForm(message, otherValues, prop => FormConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); }
private void ReadSortConfiguration(ref IFilterRequest message, JProperty property) { int separatorIndex = property.Name.LastIndexOf("_"); int index = Convert.ToInt32(property.Name.Substring(separatorIndex + 1)); string propertyName = property.Name.Substring(0, separatorIndex); while (index >= message.Sort.Count) message.Sort.Add(new Sort()); if (propertyName == "iSortCol") message.Sort[index].Column = property.Value.ToObject<int>(); else if (propertyName == "sSortDir") message.Sort[index].Direction = property.Value.ToObject<string>().AsSortDirection(); }
private void ReadSortConfiguration(ref IFilterRequest message, JProperty property) { Match match = Regex.Match(property.Name, @"order\[([0-9]+)\](.+)"); if (match.Success && match.Groups.Count == 3) { int index = Convert.ToInt32(match.Groups[1].Value); string propertyName = match.Groups[2].Value; while (index >= message.Sort.Count) message.Sort.Add(new Sort()); if (propertyName == "[column]") message.Sort[index].Column = property.Value.ToObject<int>(); else if (propertyName == "[dir]") message.Sort[index].Direction = property.Value.ToObject<string>().AsSortDirection(); } }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { IValueProvider valueProvider = bindingContext.ValueProvider; IFilterRequest message = Activator.CreateInstance(_concreteType) as IFilterRequest; message.Draw = GetValue <int>(valueProvider, "sEcho"); message.Start = GetValue <int>(valueProvider, "iDisplayStart"); message.Length = GetValue <int>(valueProvider, "iDisplayLength"); message.Search.Value = GetValue <string>(valueProvider, "sSearch"); message.Search.IsRegex = GetValue <bool>(valueProvider, "bEscapeRegex"); message.Sort.Capacity = GetValue <int>(valueProvider, "iSortingCols"); for (int i = 0; i < message.Sort.Capacity; i++) { ISort sort = new Sort(); sort.Column = GetValue <int>(valueProvider, "iSortCol_" + i); sort.Direction = GetValue <string>(valueProvider, "sSortDir_" + i).AsSortDirection(); message.Sort.Add(sort); } int totalColumns = GetValue <int>(valueProvider, "iColumns"); for (int i = 0; i < totalColumns; i++) { IColumn column = new Column(); column.Data = GetValue <string>(valueProvider, "mDataProp_" + i); column.Searchable = GetValue <bool>(valueProvider, "bSearchable_" + i); column.Sortable = GetValue <bool>(valueProvider, "bSortable_" + i); column.Search.Value = GetValue <string>(valueProvider, "sSearch_" + i); column.Search.IsRegex = GetValue <bool>(valueProvider, "bRegex_" + i); message.Columns.Add(i, column); } FormConvertHelper.ReadForm(message, valueProvider, prop => FormConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); return(message); }
private void ReadColumnConfiguration(ref IFilterRequest message, JProperty property) { int separatorIndex = property.Name.LastIndexOf("_"); int index = Convert.ToInt32(property.Name.Substring(separatorIndex + 1)); string propertyName = property.Name.Substring(0, separatorIndex); IColumn currentColumn = null; if (!message.HasColumn(index)) { currentColumn = new Column(); message.Columns.Add(index, currentColumn); } else { currentColumn = message.GetColumn(index); } if (propertyName == "mDataProp") { currentColumn.Data = property.Value.ToObject <string>(); } else if (propertyName == "bSearchable") { currentColumn.Searchable = property.Value.ToObject <bool>(); } else if (propertyName == "bSortable") { currentColumn.Sortable = property.Value.ToObject <bool>(); } else if (propertyName == "sSearch") { currentColumn.Search.Value = property.Value.ToObject <string>(); } else if (propertyName == "bRegex") { currentColumn.Search.IsRegex = property.Value.ToObject <bool>(); } }
private void ReadSortConfiguration(ref IFilterRequest message, JProperty property) { int separatorIndex = property.Name.LastIndexOf("_"); int index = Convert.ToInt32(property.Name.Substring(separatorIndex + 1)); string propertyName = property.Name.Substring(0, separatorIndex); while (index >= message.Sort.Count) { message.Sort.Add(new Sort()); } if (propertyName == "iSortCol") { message.Sort[index].Column = property.Value.ToObject <int>(); } else if (propertyName == "sSortDir") { message.Sort[index].Direction = property.Value.ToObject <string>().AsSortDirection(); } }
private void ReadColumnConfiguration(ref IFilterRequest message, JProperty property) { Match match = Regex.Match(property.Name, @"columns\[([0-9]+)\](.+)"); if (match.Success && match.Groups.Count == 3) { int index = Convert.ToInt32(match.Groups[1].Value); string propertyName = match.Groups[2].Value; IColumn currentColumn = null; if (!message.HasColumn(index)) { currentColumn = new Column(); message.Columns.Add(index, currentColumn); } else currentColumn = message.GetColumn(index); if (propertyName == "[data]") currentColumn.Data = property.Value.ToObject<string>(); else if (propertyName == "[name]") currentColumn.Name = property.Value.ToObject<string>(); else if (propertyName == "[searchable]") currentColumn.Searchable = property.Value.ToObject<bool>(); else if (propertyName == "[orderable]") currentColumn.Sortable = property.Value.ToObject<bool>(); else if (propertyName == "[search][value]") currentColumn.Search.Value = property.Value.ToObject<string>(); else if (propertyName == "[search][regex]") currentColumn.Search.IsRegex = property.Value.ToObject<bool>(); } }
public virtual IPageResponse <TSource> Process <TSource>(IQueryable <TSource> query, IFilterRequest request, Func <IQueryable <TSource>, IQueryable <TSource> > appendQuery = null) { // Causes an extra evaluation int totalRecords = query.Count(); IQueryable <TSource> filteredData = query; if (_filterProcessor != null) { filteredData = _filterProcessor.ApplyFiltersAndSort(request, query); } if (appendQuery != null) { filteredData = appendQuery(filteredData); } int totalDisplayRecords = filteredData.Count(); IQueryable <TSource> skipped = filteredData.Skip(request.Start); IQueryable <TSource> page = request.Length <= 0 ? skipped : skipped.Take(request.Length); TSource[] dataSource = page.ToArray(); return(new PageResponse <TSource>(request.Draw, totalRecords, totalDisplayRecords, dataSource)); }
/// <typeparam name="TSource">The type of the source query</typeparam> /// <param name="query">A queryable for the data.</param> /// <param name="request">The request filters</param> /// /// <param name="outputType">The output type</param> /// <returns>The action result</returns> public static PlainDataTableResult <TSource> CreatePlain <TSource>(IQueryable <TSource> query, IFilterRequest request, OutputType?outputType = null) { var result = new PlainDataTableResult <TSource>(query, request, outputType); return(result); }
public SqlWhereBuilder(IFilterRequest request, Dictionary <string, string> columns) { _request = request; _columns = columns; _parameters = new Dictionary <string, object>(); }
public static PlainDataTableResult <TSource> CreatePlainFromCollection <TSource>(ICollection <TSource> q, IFilterRequest request, OutputType?outputType = null) { return(CreatePlain(q.AsQueryable(), request, outputType)); }
/// <typeparam name="TSource">The type of the source query</typeparam> /// <typeparam name="TTransform">The type of the result</typeparam> /// <param name="query">A queryable for the data</param> /// <param name="request">The request filters</param> /// <param name="transform">A transform for custom column rendering e.g. to do a custom date row => new { CreatedDate = row.CreatedDate.ToString("dd MM yy") }</param> /// <param name="outputType">The output type</param> /// <returns>The action result</returns> public static MutableDataTableResult CreateMutable <TSource, TTransform>(IQueryable <TSource> query, IFilterRequest request, Func <TSource, TTransform> transform, OutputType?outputType = null, ArrayOutputType?arrayOutputType = null) { var result = new MutableDataTableResult(query.Cast <object>(), request, outputType); result.Data = result.Data .Transform <TSource, Dictionary <string, object> >(row => TransformTypeInfo.MergeTransformValuesIntoDictionary(transform, row)) .Transform <Dictionary <string, object>, Dictionary <string, object> >(StringTransformers.StringifyValues); result.Data = ApplyOutputRulesForMutable(result.Data, arrayOutputType); return(result); }
public static MutableDataTableResult CreateMutable <TSource>(IQueryable <TSource> query, IFilterRequest request, OutputType?outputType = null, ArrayOutputType?arrayOutputType = null) { var result = new MutableDataTableResult(query.Cast <object>(), request, outputType); result.Data = result.Data .Transform <TSource, Dictionary <string, object> >(DataTablesTypeInfo <TSource> .ToDictionary) .Transform <Dictionary <string, object>, Dictionary <string, object> >(StringTransformers.StringifyValues); result.Data = ApplyOutputRulesForMutable(result.Data, arrayOutputType); return(result); }
public static MutableDataTableResult CreateMutableFromCollection <TSource>(ICollection <TSource> q, IFilterRequest request, OutputType?outputType = null, ArrayOutputType?arrayOutputType = null) { return(CreateMutable(q.AsQueryable(), request, outputType, arrayOutputType)); }
public virtual IQueryable <T> ApplyFiltersAndSort <T>(IFilterRequest filter, IQueryable <T> data) { var outputProperties = DataTablesTypeInfo <T> .Properties; return(ApplyFiltersAndSort <T>(filter, data, outputProperties)); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); IFilterRequest message = value as IFilterRequest; if (message != null) { writer.WritePropertyName("draw"); writer.WriteValue(message.Draw); writer.WritePropertyName("start"); writer.WriteValue(message.Start); writer.WritePropertyName("length"); writer.WriteValue(message.Length); if (!string.IsNullOrWhiteSpace(message.Search.Value)) { writer.WritePropertyName("search[value]"); writer.WriteValue(message.Search.Value); writer.WritePropertyName("search[regex]"); writer.WriteValue(message.Search.IsRegex); } for (int i = 0; i < message.Sort.Count; i++) { writer.WritePropertyName(string.Format("order[{0}][column]", i)); writer.WriteValue(message.Sort[i].Column); writer.WritePropertyName(string.Format("order[{0}][dir]", i)); writer.WriteValue(message.Sort[i].Direction.AsString()); } foreach (KeyValuePair <int, IColumn> column in message.Columns.OrderBy(x => x.Key)) { writer.WritePropertyName(string.Format("columns[{0}][data]", column.Key)); writer.WriteValue(column.Value.Data); writer.WritePropertyName(string.Format("columns[{0}][name]", column.Key)); writer.WriteValue(column.Value.Name); writer.WritePropertyName(string.Format("columns[{0}][searchable]", column.Key)); writer.WriteValue(column.Value.Searchable); writer.WritePropertyName(string.Format("columns[{0}][orderable]", column.Key)); writer.WriteValue(column.Value.Sortable); if (!string.IsNullOrWhiteSpace(column.Value.Search.Value)) { writer.WritePropertyName(string.Format("columns[{0}][search][value]", column.Key)); writer.WriteValue(column.Value.Search.Value); writer.WritePropertyName(string.Format("columns[{0}][search][regex]", column.Key)); writer.WriteValue(column.Value.Search.IsRegex); } } } JsonConvertHelper.WriteJson(message, writer, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); writer.WriteEndObject(); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jsonObject = JObject.Load(reader); IEnumerable <JProperty> properties = jsonObject.Properties(); Dictionary <string, JProperty> otherProperties = new Dictionary <string, JProperty>(); IFilterRequest message = Activator.CreateInstance(objectType) as IFilterRequest; foreach (JProperty property in properties) { if (property.Name == "sEcho") { message.Draw = property.Value.ToObject <int>(); } else if (property.Name == "iDisplayStart") { message.Start = property.Value.ToObject <int>(); } else if (property.Name == "iDisplayLength") { message.Length = property.Value.ToObject <int>(); } else if (property.Name == "sSearch") { message.Search.Value = property.Value.ToObject <string>(); } else if (property.Name == "bEscapeRegex") { message.Search.IsRegex = property.Value.ToObject <bool>(); } else if (property.Name == "iSortingCols") { message.Sort.Capacity = property.Value.ToObject <int>(); } else if (property.Name == "iColumns") { continue; } else if (property.Name.StartsWith("iSortCol") || property.Name.StartsWith("sSortDir")) { ReadSortConfiguration(ref message, property); } else if (property.Name.StartsWith("mDataProp") || property.Name.StartsWith("bSearchable") || property.Name.StartsWith("bSortable") || property.Name.StartsWith("sSearch") || property.Name.StartsWith("bRegex")) { ReadColumnConfiguration(ref message, property); } else { otherProperties.Add(property.Name, property); } } JsonConvertHelper.ReadJson(message, otherProperties, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); return(message); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); IFilterRequest message = value as IFilterRequest; if (message != null) { writer.WritePropertyName("sEcho"); writer.WriteValue(message.Draw); writer.WritePropertyName("iDisplayStart"); writer.WriteValue(message.Start); writer.WritePropertyName("iDisplayLength"); writer.WriteValue(message.Length); if (!string.IsNullOrWhiteSpace(message.Search.Value)) { writer.WritePropertyName("sSearch"); writer.WriteValue(message.Search.Value); writer.WritePropertyName("bEscapeRegex"); writer.WriteValue(message.Search.IsRegex); } writer.WritePropertyName("iColumns"); writer.WriteValue(message.Columns.Count); writer.WritePropertyName("iSortingCols"); writer.WriteValue(message.Sort.Count); for (int i = 0; i < message.Sort.Count; i++) { writer.WritePropertyName("iSortCol_" + i); writer.WriteValue(message.Sort[i].Column); writer.WritePropertyName("sSortDir_" + i); writer.WriteValue(message.Sort[i].Direction.AsString()); } foreach (KeyValuePair <int, IColumn> column in message.Columns.OrderBy(x => x.Key)) { writer.WritePropertyName("mDataProp_" + column.Key); writer.WriteValue(column.Value.Data); writer.WritePropertyName("bSearchable_" + column.Key); writer.WriteValue(column.Value.Searchable); writer.WritePropertyName("bSortable_" + column.Key); writer.WriteValue(column.Value.Sortable); if (!string.IsNullOrWhiteSpace(column.Value.Search.Value)) { writer.WritePropertyName("sSearch_" + column.Key); writer.WriteValue(column.Value.Search.Value); writer.WritePropertyName("bRegex_" + column.Key); writer.WriteValue(column.Value.Search.IsRegex); } } } JsonConvertHelper.WriteJson(message, writer, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); writer.WriteEndObject(); }
public virtual IQueryable <T> ApplyFiltersAndSort <T>(IFilterRequest filter, IQueryable <T> data, DataTablesPropertyInfo[] objColumns) { if (!string.IsNullOrEmpty(filter.Search.Value)) { var parts = new List <string>(); var parameters = new List <object>(); for (var i = 0; i < filter.Columns.Count; i++) { if (filter.Columns[i].Searchable) { try { string currentColumnSource = !string.IsNullOrWhiteSpace(filter.Columns[i].Name) ? filter.Columns[i].Name : filter.Columns[i].Data; var currentColumn = objColumns.SingleOrDefault(x => x.Name == currentColumnSource); if (currentColumn == null && objColumns.Length > i) { currentColumn = objColumns[i]; } if (currentColumn != null) { var filterClause = GetFilterClause(filter.Search.Value, currentColumn, parameters); if (string.IsNullOrWhiteSpace(filterClause) == false) { parts.Add(filterClause); } } } catch (Exception) { // If the clause doesn't work, skip it! } } } var values = parts.Where(p => p != null); string searchQuery = string.Join(" or ", values); if (string.IsNullOrWhiteSpace(searchQuery) == false) { data = data.Where(searchQuery, parameters.ToArray()); } } foreach (KeyValuePair <int, IColumn> column in filter.Columns.OrderBy(x => x.Key)) { if (column.Value.Searchable) { var searchColumn = column.Value.Search; if (!string.IsNullOrWhiteSpace(searchColumn.Value)) { string currentColumnSource = !string.IsNullOrWhiteSpace(column.Value.Name) ? column.Value.Name : column.Value.Data; var currentColumn = objColumns.SingleOrDefault(x => x.Name == currentColumnSource); if (currentColumn == null && objColumns.Length > column.Key) { currentColumn = objColumns[column.Key]; } if (currentColumn != null) { var parameters = new List <object>(); var filterClause = GetFilterClause(searchColumn.Value, currentColumn, parameters); if (string.IsNullOrWhiteSpace(filterClause) == false) { data = data.Where(filterClause, parameters.ToArray()); } } } } } string sortString = ""; for (int i = 0; i < filter.Sort.Count; i++) { int columnNumber = filter.Sort[i].Column; if (columnNumber < filter.Columns.Count) { string currentColumnSource = !string.IsNullOrWhiteSpace(filter.Columns[columnNumber].Name) ? filter.Columns[columnNumber].Name : filter.Columns[columnNumber].Data; var currentColumn = objColumns.SingleOrDefault(x => x.Name == currentColumnSource); if (currentColumn == null && objColumns.Length > columnNumber) { currentColumn = objColumns[columnNumber]; } if (currentColumn != null) { string columnName = currentColumn.PropertyInfo.Name; string sortDir = filter.Sort[i].Direction.AsString(); if (i != 0) { sortString += ", "; } sortString += columnName + " " + sortDir; } } } if (string.IsNullOrWhiteSpace(sortString) && objColumns.Length > 0) { sortString = objColumns[0].PropertyInfo.Name; } if (!string.IsNullOrWhiteSpace(sortString)) { data = data.OrderBy(sortString); } return(data); }