Esempio n. 1
0
        public static IEnumerable <T> Order <T>(this IEnumerable <T> entities, JQueryDatatablesParam searchParams)
        {
            var propertyName = searchParams.SortColumnName();

            var enumerable = entities as IList <T> ?? entities.ToList();

            if (!enumerable.Any() || string.IsNullOrEmpty(propertyName))
            {
                return(enumerable);
            }

            var propertyInfo = enumerable.First().GetType().GetTypeInfo().GetProperty(propertyName,
                                                                                      BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

            return(searchParams.sSortDir_0 == SortAsending
                ? enumerable.OrderBy(e => propertyInfo.GetValue(e, null))
                : enumerable.OrderByDescending(e => propertyInfo.GetValue(e, null)));
        }
Esempio n. 2
0
        public static string SortColumnName(this JQueryDatatablesParam datatablesParam)
        {
            var columnNames = datatablesParam.sColumns.Split(',');

            return(columnNames[datatablesParam.iSortCol_0]);
        }