protected override void ConfigureAdditionalOptions(DataTablesConfiguration configuration, IList <DataTablesColumn <TEntity, TEntityViewModel> > columns) { configuration.AdditionalOptions["stateSave"] = false; configuration.AdditionalOptions["colReorder"] = true; configuration.AdditionalOptions["scrollX"] = true; configuration.AdditionalOptions["pagingType"] = "full_numbers"; configuration.AdditionalOptions["search"] = new { smart = true }; }
protected override void ConfigureAdditionalOptions(DataTablesConfiguration configuration, IList <DataTablesColumn <Person, PersonViewModel> > columns) { base.ConfigureAdditionalOptions(configuration, columns); configuration.AdditionalOptions["stateSave"] = true; configuration.AdditionalOptions["pagingType"] = "full_numbers"; configuration.AdditionalOptions["search"] = new { smart = true }; }
public Task BindModelAsync(ModelBindingContext bindingContext) { string controllerName = bindingContext.ActionContext.ActionDescriptor.RouteValues["controller"]; string actionName = bindingContext.ActionContext.ActionDescriptor.RouteValues["action"]; DataTablesConfiguration configuration = dataTablesService.GetConfiguration(controllerName, actionName); bindingContext.Result = ModelBindingResult.Success(configuration); return(Task.CompletedTask); }
public Task BindModelAsync(ModelBindingContext bindingContext) { var request = bindingContext.HttpContext.Request; IFormCollection value = request.HasFormContentType ? request.Form : FormCollection.Empty; string controllerName = bindingContext.ActionContext.ActionDescriptor.RouteValues["controller"]; string actionName = bindingContext.ActionContext.ActionDescriptor.RouteValues["action"]; DataTablesConfiguration configuration = dataTablesService.GetConfiguration(controllerName, actionName); var inputModel = DataTablesInputModel.FromFormCollection(value, configuration); bindingContext.Result = ModelBindingResult.Success(inputModel); return(Task.CompletedTask); }
public DataTablesConfiguration GetConfiguration(string controllerName, string actionName) { (controllerName, actionName) = SanitizeNames(controllerName, actionName); string configurationName = $"DataTables:{controllerName}.{actionName}"; var configurationObject = new DataTablesConfiguration(); configurationObject.Endpoint = urlHelper.Action($"{actionName}Data", controllerName); var section = configuration.GetSection(configurationName); if (!section.Exists()) { throw new InvalidOperationException($"Sezione di configurazione '{configurationName}' non trovata. Verifica di averla creata nel file appsettings.json (o in altra fonte di configurazione)."); } section.Bind(configurationObject); return(configurationObject); }
protected override void ConfigureAdditionalOptions(DataTablesConfiguration configuration, IList <DataTablesColumn <Person, PersonViewModel> > columns) { base.ConfigureAdditionalOptions(configuration, columns); configuration.AdditionalOptions["stateSave"] = true; }
public DataTablesRequestHandler(DataTablesConfiguration <T> configuration) { Configuration = configuration; }
public DataTablesRequestHandler(string configurationName) { Configuration = DataTablesConfiguration <T> .Get(configurationName) ?? DataTablesConfiguration <T> .GetDefault(); }
public SqlDataTablesRequestHandler(IDbConnection connection, DataTablesConfiguration <T> configuration) : base(configuration) { Connection = connection; }
public IActionResult Index(DataTablesConfiguration configuration) { return(View(configuration)); }
protected override void ConfigureAdditionalOptions(DataTablesConfiguration configuration, IList <DataTablesColumn <TEntity, TEntityViewModel> > columns) { configuration.AdditionalOptions["stateSave"] = false; }
public static DataTablesColumnModel FromValueProvider(Func <string, string> valueProvider, int columnIndex, DataTablesConfiguration configuration) { string prefix = $"colums[{columnIndex}]"; string columnName = valueProvider($"columns[{columnIndex}][name]"); if (columnName == null) { throw new IndexOutOfRangeException($"Cannot create column with index {columnIndex}"); } DataTablesColumnDefinition columnDefinition = configuration.ColumnDefinitions.SingleOrDefault(col => col.Name == columnName); if (columnDefinition == null) { throw new InvalidOperationException($"Cannot create column '{columnName}' since it's not supported"); } string search = string.Empty; if (columnDefinition.Searchable) { search = valueProvider($"columns[{columnIndex}][search][value]"); } int orderIndex = 0; string columnReferenceIndex = null; var sortingDirection = DataTablesSortingDirection.None; int? sortingPriority = null; if (columnDefinition.Sortable) { do { columnReferenceIndex = valueProvider($"order[{orderIndex}][column]"); if (columnReferenceIndex == columnIndex.ToString()) { sortingDirection = "desc".Equals(valueProvider($"order[{orderIndex}][dir]"), StringComparison.InvariantCultureIgnoreCase) ? DataTablesSortingDirection.Descending : DataTablesSortingDirection.Ascending; break; } orderIndex++; } while (!string.IsNullOrWhiteSpace(columnReferenceIndex)); if (sortingDirection != DataTablesSortingDirection.None) { sortingPriority = orderIndex; } } return(new DataTablesColumnModel(columnName, search, columnDefinition.GloballySearchable, sortingDirection, sortingPriority)); }
public static DataTablesInputModel FromValueProvider(Func <string, string> valueProvider, DataTablesConfiguration configuration) { int.TryParse(valueProvider("draw"), out int draw); int.TryParse(valueProvider("start"), out int start); int.TryParse(valueProvider("length"), out int length); string search = valueProvider("search[value]"); var columnDefinitions = new List <DataTablesColumnModel>(); int columnIndex = 0; while (true) { try { var columnModel = DataTablesColumnModel.FromValueProvider(valueProvider, columnIndex++, configuration); columnDefinitions.Add(columnModel); } catch (IndexOutOfRangeException) { break; } catch { continue; } } return(new DataTablesInputModel(configuration.TableName, draw, start, length, search, columnDefinitions.AsReadOnly())); }
public static object FromFormCollection(IFormCollection value, DataTablesConfiguration configuration) { Func <string, string> valueProvider = (string key) => value[key]; return(FromValueProvider(valueProvider, configuration)); }
public static DataTablesInputModel FromNameValueCollection(NameValueCollection nameValueCollection, DataTablesConfiguration configuration) { Func <string, string> valueProvider = (string key) => nameValueCollection.Get(key); return(FromValueProvider(valueProvider, configuration)); }
public static DataTablesInputModel FromQueryString(string queryString, DataTablesConfiguration configuration) { var nameValueCollection = string.IsNullOrWhiteSpace(queryString) ? new NameValueCollection() : HttpUtility.ParseQueryString(queryString); return(FromNameValueCollection(nameValueCollection, configuration)); }