private IQueryable <Character> SortCharacters(IQueryable <Character> charactersQueryable, string sortingDefition, JqGridSortingOrders sortingOrder) { IOrderedEnumerable <Character> orderedCharacters = null; if (!String.IsNullOrWhiteSpace(sortingDefition)) { sortingDefition = sortingDefition.ToLowerInvariant(); string[] subSortingDefinitions = sortingDefition.Split(','); foreach (string subSortingDefinition in subSortingDefinitions) { string[] sortingDetails = subSortingDefinition.Trim().Split(' '); string sortingDetailsName = sortingDetails[0]; JqGridSortingOrders sortingDetailsOrder = (sortingDetails.Length > 1) ? (JqGridSortingOrders)Enum.Parse(typeof(JqGridSortingOrders), sortingDetails[1], true) : sortingOrder; Func <Character, object> sortingExpression = GetCharacterSortingExpression(sortingDetailsName, sortingDetailsOrder); if (sortingExpression != null) { if (orderedCharacters != null) { orderedCharacters = (sortingDetailsOrder == JqGridSortingOrders.Asc) ? orderedCharacters.ThenBy(sortingExpression) : orderedCharacters.ThenByDescending(sortingExpression); } else { orderedCharacters = (sortingDetailsOrder == JqGridSortingOrders.Asc) ? charactersQueryable.OrderBy(sortingExpression) : charactersQueryable.OrderByDescending(sortingExpression); } } } } return(orderedCharacters.AsQueryable()); }
private JqGridRequest BindSortingProperties(JqGridRequest model, ModelBindingContext bindingContext) { if (!String.IsNullOrWhiteSpace(JqGridRequest.ParametersNames.SortingName)) { string sortingName = bindingContext.ValueProvider.GetValue(JqGridRequest.ParametersNames.SortingName).FirstValue; if (!String.IsNullOrWhiteSpace(sortingName)) { model.SortingName = sortingName; } } if (!String.IsNullOrWhiteSpace(JqGridRequest.ParametersNames.SortingOrder)) { JqGridSortingOrders sortingOrder = JqGridSortingOrders.Asc; string sortingOrderAsString = bindingContext.ValueProvider.GetValue(JqGridRequest.ParametersNames.SortingOrder).FirstValue; if (!String.IsNullOrWhiteSpace(sortingOrderAsString) && Enum.TryParse(sortingOrderAsString, true, out sortingOrder)) { model.SortingOrder = sortingOrder; } } return(model); }
/// <summary> /// Initializes a new instance of the JqGridColumnSortingNameAttribute class. /// </summary> /// <param name="sortable">If this column can be sorted</param> public JqGridColumnSortableAttribute(bool sortable) { Sortable = sortable; SortType = JqGridOptionsDefaults.ColumnModel.Sorting.Type; SortFunction = String.Empty; InitialSortingOrder = JqGridOptionsDefaults.ColumnModel.Sorting.InitialOrder; }
/// <summary> /// Initializes a new instance of the JqGridColumnSortingNameAttribute class. /// </summary> /// <param name="sortable">If this column can be sorted</param> public JqGridColumnSortableAttribute(bool sortable) { Sortable = sortable; SortType = JqGridColumnSortTypes.Text; SortFunction = String.Empty; InitialSortingOrder = JqGridSortingOrders.Asc; }
private Func <Planet, object> GetPlanetSortingExpression(string sortingName, JqGridSortingOrders sortingOrder) { Func <Planet, object> sortingExpression = null; switch (sortingName) { case "id": sortingExpression = (planet => planet.Id); break; case "name": sortingExpression = (planet => planet.Name); break; case "diameter": sortingExpression = (planet => planet.Diameter ?? ((sortingOrder == JqGridSortingOrders.Asc) ? Int32.MaxValue : Int32.MinValue)); break; case "rotationperiod": sortingExpression = (planet => planet.RotationPeriod ?? ((sortingOrder == JqGridSortingOrders.Asc) ? Int32.MaxValue : Int32.MinValue)); break; case "orbitalperiod": sortingExpression = (planet => planet.OrbitalPeriod ?? ((sortingOrder == JqGridSortingOrders.Asc) ? Int32.MaxValue : Int32.MinValue)); break; case "gravity": sortingExpression = (planet => { int gravity = (sortingOrder == JqGridSortingOrders.Asc) ? Int32.MaxValue : Int32.MinValue; if (!String.IsNullOrWhiteSpace(planet.Gravity)) { gravity = Convert.ToInt32(planet.Gravity.Replace(" standard", String.Empty), CultureInfo.InvariantCulture); } return(gravity); }); break; case "population": sortingExpression = (planet => planet.Population ?? ((sortingOrder == JqGridSortingOrders.Asc) ? UInt64.MaxValue : UInt64.MinValue)); break; default: break; } return(sortingExpression); }
public MyJqGridHelper(string id = "Grid", string afterInsertRow = null, string afterEditCell = null, string afterRestoreCell = null, string afterSaveCell = null, string afterSubmitCell = null, string altClass = "ui-priority-secondary", bool altRows = false, bool autoEncode = false, bool autoWidth = true, string beforeRequest = null, string beforeSelectRow = null, string beforeEditCell = null, string beforeSaveCell = null, string beforeSubmitCell = null, string caption = null, int cellLayout = 5, bool cellEditingEnabled = false, JqGridCellEditingSubmitModes cellEditingSubmitMode = JqGridCellEditingSubmitModes.Remote, string cellEditingUrl = null, string dataString = null, JqGridDataTypes dataType = JqGridDataTypes.Json, bool deepEmpty = false, JqGridLanguageDirections direction = JqGridLanguageDirections.Ltr, JqGridDynamicScrollingModes dynamicScrollingMode = JqGridDynamicScrollingModes.Disabled, int dynamicScrollingTimeout = 200, string editingUrl = null, string emptyRecords = "No resultes found.", bool expandColumnClick = true, string expandColumn = null, int?height = null, string errorCell = null, string formatCell = null, bool footerEnabled = false, bool gridView = false, bool groupingEnabled = false, JqGridGroupingView groupingView = null, bool headerTitles = false, bool hidden = false, bool hiddenEnabled = true, bool ignoreCase = true, JqGridJsonReader jsonReader = null, string loadBeforeSend = null, string loadError = null, string loadComplete = null, bool loadOnce = true, JqGridMethodTypes methodType = JqGridMethodTypes.Get, JqGridMultiKeys?multiKey = null, bool multiBoxOnly = false, bool multiSelect = false, int multiSelectWidth = 20, bool multiSort = false, string gridComplete = null, string onCellSelect = null, string onDoubleClickRow = null, string onHeaderClick = null, string onInitGrid = null, string onPaging = null, string onRightClickRow = null, string onSelectAll = null, string onSelectCell = null, string onSelectRow = null, string onSortCol = null, bool pager = true, JqGridParametersNames parametersNames = null, object postData = null, string postDataScript = null, string resizeStart = null, string resizeStop = null, string rowAttributes = null, List <int> rowsList = null, int rowsNumber = 20, bool rowsNumbers = false, int rowsNumbersWidth = 25, bool shrinkToFit = true, int scrollOffset = 18, string serializeCellData = null, string serializeGridData = null, string serializeSubGridData = null, bool sortable = false, string sortingName = "", JqGridSortingOrders sortingOrder = JqGridSortingOrders.Asc, bool subgridEnabled = false, JqGridSubgridModel subgridModel = null, object subgridHelper = null, string subgridUrl = null, int subgridColumnWidth = 20, string subGridBeforeExpand = null, string subGridRowColapsed = null, string subGridRowExpanded = null, bool topPager = false, bool treeGridEnabled = false, JqGridTreeGridModels treeGridModel = JqGridTreeGridModels.Nested, string url = null, bool userDataOnFooter = false, bool viewRecords = true, int?width = null) : base(id, afterInsertRow, afterEditCell, afterRestoreCell, afterSaveCell, afterSubmitCell, altClass, altRows, autoEncode, autoWidth, beforeRequest, beforeSelectRow, beforeEditCell, beforeSaveCell, beforeSubmitCell, caption, cellLayout, cellEditingEnabled, cellEditingSubmitMode, cellEditingUrl, dataString, dataType, deepEmpty, direction, dynamicScrollingMode, dynamicScrollingTimeout, editingUrl, emptyRecords, expandColumnClick, expandColumn, height, errorCell, formatCell, footerEnabled, gridView, groupingEnabled, groupingView, headerTitles, hidden, hiddenEnabled, ignoreCase, jsonReader, loadBeforeSend, loadError, loadComplete, loadOnce, methodType, multiKey, multiBoxOnly, multiSelect, multiSelectWidth, multiSort, gridComplete, onCellSelect, onDoubleClickRow, onHeaderClick, onInitGrid, onPaging, onRightClickRow, onSelectAll, onSelectCell, onSelectRow, onSortCol, pager, parametersNames, postData, postDataScript, resizeStart, resizeStop, rowAttributes, rowsList, rowsNumber, rowsNumbers, rowsNumbersWidth, shrinkToFit, scrollOffset, serializeCellData, serializeGridData, serializeSubGridData, sortable, sortingName, sortingOrder, subgridEnabled, subgridModel, subgridHelper, subgridUrl, subgridColumnWidth, subGridBeforeExpand, subGridRowColapsed, subGridRowExpanded, topPager, treeGridEnabled, treeGridModel, url, userDataOnFooter, viewRecords, width) { }
internal static void SetColumnInitialSortingOrder(this ModelMetadata metadata, JqGridSortingOrders initialSortingOrder) { metadata.AdditionalValues.Add(_initialSortingOrderKey, initialSortingOrder); }
private IQueryable <Planet> SortPlanets(IQueryable <Planet> planetsQueryable, string sortingName, JqGridSortingOrders sortingOrder) { IOrderedEnumerable <Planet> orderedPlanets = null; if (!String.IsNullOrWhiteSpace(sortingName)) { sortingName = sortingName.ToLowerInvariant(); Func <Planet, object> sortingExpression = GetPlanetSortingExpression(sortingName, sortingOrder); if (sortingExpression != null) { orderedPlanets = (sortingOrder == JqGridSortingOrders.Asc) ? planetsQueryable.OrderBy(sortingExpression) : planetsQueryable.OrderByDescending(sortingExpression); } } return(orderedPlanets.AsQueryable()); }
private Func <Character, object> GetCharacterSortingExpression(string sortingName, JqGridSortingOrders sortingOrder) { Func <Character, object> sortingExpression = null; switch (sortingName) { case "id": sortingExpression = (character => character.Id); break; case "name": sortingExpression = (character => character.Name); break; case "gender": sortingExpression = (character => (int?)character.Gender ?? ((sortingOrder == JqGridSortingOrders.Asc) ? Int32.MinValue : Int32.MaxValue)); break; case "height": sortingExpression = (character => character.Height); break; case "weight": sortingExpression = (character => character.Weight ?? ((sortingOrder == JqGridSortingOrders.Asc) ? Int32.MaxValue : Int32.MinValue)); break; case "birthyear": sortingExpression = (character => { decimal birthYear = (sortingOrder == JqGridSortingOrders.Asc) ? Int32.MaxValue : Int32.MinValue; if (!String.IsNullOrWhiteSpace(character.BirthYear)) { if (character.BirthYear.EndsWith("BBY", StringComparison.OrdinalIgnoreCase)) { birthYear = (-1) * Convert.ToDecimal(character.BirthYear.Substring(0, character.BirthYear.Length - 3), CultureInfo.InvariantCulture); } else if (character.BirthYear.EndsWith("ABY", StringComparison.OrdinalIgnoreCase)) { birthYear = Convert.ToDecimal(character.BirthYear.Substring(0, character.BirthYear.Length - 3), CultureInfo.InvariantCulture); } } return(birthYear); }); break; default: break; } return(sortingExpression); }