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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 6
0
        protected override void ConfigureAdditionalOptions(DataTablesConfiguration configuration, IList <DataTablesColumn <Person, PersonViewModel> > columns)
        {
            base.ConfigureAdditionalOptions(configuration, columns);

            configuration.AdditionalOptions["stateSave"] = true;
        }
Esempio n. 7
0
 public DataTablesRequestHandler(DataTablesConfiguration <T> configuration)
 {
     Configuration = configuration;
 }
Esempio n. 8
0
 public DataTablesRequestHandler(string configurationName)
 {
     Configuration = DataTablesConfiguration <T> .Get(configurationName) ?? DataTablesConfiguration <T> .GetDefault();
 }
Esempio n. 9
0
 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;
 }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
        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()));
        }
Esempio n. 14
0
        public static object FromFormCollection(IFormCollection value, DataTablesConfiguration configuration)
        {
            Func <string, string> valueProvider = (string key) => value[key];

            return(FromValueProvider(valueProvider, configuration));
        }
Esempio n. 15
0
        public static DataTablesInputModel FromNameValueCollection(NameValueCollection nameValueCollection, DataTablesConfiguration configuration)
        {
            Func <string, string> valueProvider = (string key) => nameValueCollection.Get(key);

            return(FromValueProvider(valueProvider, configuration));
        }
Esempio n. 16
0
        public static DataTablesInputModel FromQueryString(string queryString, DataTablesConfiguration configuration)
        {
            var nameValueCollection = string.IsNullOrWhiteSpace(queryString) ? new NameValueCollection() : HttpUtility.ParseQueryString(queryString);

            return(FromNameValueCollection(nameValueCollection, configuration));
        }