Example #1
0
        public static Configurator <Contract, ContractRow> ConfigureFormWatcher(
            this Configurator <Contract, ContractRow> conf)
        {
            conf.Table();
            conf.Column(c => c.StartDate)
            .FilterRange(c => c.StartDate, c => c.ClientFiltering().HideFilter());
            conf.Column(c => c.Supplier)
            .FilterValue(c => c.Supplier, x => x.ClientFiltering().HideFilter());

            conf.WatchForm <WatchedFormViewModel>(w =>
            {
                w.WatchAllFields();
                w.Field(x => x.Supplier).TriggerSearchOnEvents(10, "keyup").DoNotEmbedToQuery();
                w.Field(x => x.Ratings).Delimiter(",");
                w.Field(x => x.PriceRanges).Selector("input[name='chb_Price']");
                w.Field(x => x.StartDateFrom).AutoDatePicker();
                w.Field(x => x.StartDateTo).AutoDatePicker();
                w.Field(x => x.FormTimeStamp).Constant(DateTime.Now);

                w.FilterColumn(conf, x => x.StartDate).FilterRange(x => x.StartDateFrom, x => x.StartDateTo).ClientServer(server: false);
                w.FilterColumn(conf, x => x.Supplier).FilterValue(x => x.Supplier).ClientServer(server: false);
            });



            conf.FreeOrdering(q =>
                              q.Form <WatchedFormViewModel>().Ordering == OrderingPreset.ByNames
                    ? Ordering.Ascending.ToFilterTuple()
                    : FilterTuple.None <Ordering>(),
                              x => x.Title);

            conf.FreeOrdering(q =>
                              q.Form <WatchedFormViewModel>().Ordering == OrderingPreset.ByPrices
                        ? Ordering.Descending.ToFilterTuple()
                        : FilterTuple.None <Ordering>(),
                              x => x.Price);

            conf.FreeFilter(q =>
                            q.Form <WatchedFormViewModel>().Ordering.ToFilterTuple(x => x == OrderingPreset.ByScopeRating),
                            (x, v) => x.OrderByDescending(c => c.Rating).ThenByDescending(c => c.Scope));

            conf.FreeFilter(q => q.Form <WatchedFormViewModel>().Title.TupleIfNotNull(), (q, v) => q.Where(x => x.Title.Contains(v)));

            conf.FreeFilter(
                q => q.Form <WatchedFormViewModel>().Ratings.TupleIfNotNull(x => x.Length > 0),
                (q, v) => q.Where(x => v.Contains(x.Rating))
                );

            conf.FreeFilter(q => q.Form <WatchedFormViewModel>().EndYear.TupleIfNotNull(),
                            (q, v) => v == -1 ? q.Where(c => c.EndDate == null) : q.Where(x => x.EndDate != null && x.EndDate.Value.Year == v));

            conf.FreeFilter(q => q.Form <WatchedFormViewModel>().Priorities.TupleIfNotNull(x => x.Length > 0),
                            (q, v) => q.Where(x => v.Contains(x.Priority) || x.Priority == Priority.Critical));

            conf.FreeFilter(q => q.Form <WatchedFormViewModel>().TupleIfNotNull(), FilterTax);
            conf.FreeFilter(q => q.Form <WatchedFormViewModel>().PriceRanges.TupleIfNotNull(c => c.Length > 0), FilterPrices);
            return(conf);
        }
        public static Configurator <User, UserRow> ConfigureRadio(this Configurator <User, UserRow> conf)
        {
            conf.Column(c => c.Id).DataOnly();
            conf.Column(c => c.LastName).Orderable(c => c.LastName);


            conf.Ordering(c => c.Radio()); //enable radio ordering
            return(conf);
        }
 // we have moved limiting, loading indicator and templating configuration to separate mixin
 // just to avoid code duplication
 public static Configurator <Product, Product> Common(this Configurator <Product, Product> conf)
 {
     conf.PrettifyTitles(firstCapitals: true);
     conf.Column(c => c.Id).DataOnly();
     conf.Column(c => c.RecentSaleDate).Title("Last order").Format("`moment({@}).fromNow()`");
     conf.Column(c => c.Rating).TemplateFunction("formatRating");
     conf.LoadingIndicator(where : "lt");
     conf.Limit(ui => ui.Values(new[] { "All", "-", "10", "20", "50", "100" }), where : "lt");
     return(conf);
 }
        public static Configurator <Toy, Row> OrderingAndLoadingInidicator(this Configurator <Toy, Row> conf)
        {
            conf.ProjectionTitlesAndDataOnly();

            conf.LoadingIndicator(where : "rt", order: 4);
            conf.Column(c => c.Price).Orderable(c => c.Price, ui => ui.DefaultOrdering(Ordering.Descending));
            conf.Column(c => c.Name).Orderable(c => c.ToyName);
            conf.Column(c => c.ItemsSold).Title("Sold (client ordering)").Orderable(c => c.ItemsLeft, ui => ui.UseClientOrdering());

            return(conf);
        }
Example #5
0
 public static Configurator <Contract, ContractRow> Table(this Configurator <Contract, ContractRow> conf)
 {
     conf.AppendEmptyFilters().PrettifyTitles(true);
     conf.Scrollbar(c => c.Vertical());
     conf.Partition(c => c.InitialSkipTake(take: 10));
     conf.Column(c => c.Id).DataOnly();
     conf.DatePicker(new DatepickerOptions(
                         "ltcCreateDatePicker",
                         "ltcPutDateToDatepicker",
                         "ltcGetDateFromDatepicker",
                         "ltcDestroyDatepicker"
                         ));
     conf.Column(c => c.StartDate).Format("`moment({@}).format('DD MMM YYYY');`");
     conf.Column(c => c.EndDate)
     .Template(x =>
     {
         x.IfNotPresent("{@}", "<i>No date</i>");
         x.Returns("`moment({@}).format('DD MMM YYYY');`");
     });
     conf.Column(c => c.Tax).Template(x =>
     {
         x.IfNotPresent("{@}", "No tax");
         x.Returns("`({@}*{Price}).toFixed(2)` ({@})");
     });
     conf.Column(c => c.Priority).FormatEnum();
     conf.Column(c => c.Scope).FormatEnum();
     conf.Column(c => c.Tax).Title("Tax");
     conf.Column(c => c.Rating).TemplateFunction("formatRating");
     return(conf);
 }
        public static Configurator <User, UserRow> Configure(this Configurator <User, UserRow> conf)
        {
            conf.Column(c => c.Id).DataOnly();

            conf.Column(c => c.LastName)
            .Orderable(c => c.LastName);     // type of C is User (TRow)

            conf.Column(c => c.UserType)
            .Orderable(c => c.UserType == UserType.Admin ? -1 : (int)c.UserType);

            conf.Column(c => c.RegistrationDate) // client ordering, but server one also persisted
            .Orderable(c => c.RegistrationDate, ui => ui.UseClientOrdering());

            return(conf);
        }
        public static Configurator <Contract, ContractRow> ConfigureSelectFilters(this Configurator <Contract, ContractRow> conf)
        {
            conf.Table();
            conf.Column(c => c.Id).DataOnly();

            // Simple select filter with default value selected
            conf.Column(c => c.Rating)
            .FilterSelect(c => c.Rating, ui => ui.SelectAny()
                          .SelectItems(new UiListItem[]
            {
                new UiListItem()
                {
                    Text = "*", Value = "1"
                },
                new UiListItem()
                {
                    Text = "**", Value = "2"
                },
                new UiListItem()
                {
                    Text = "***", Value = "3"
                },
                new UiListItem()
                {
                    Text = "****", Value = "4"
                },
                new UiListItem()
                {
                    Text = "*****", Value = "5"
                },
            }).SelectDefault(4));

            // Select filter for enumeration with client filtering
            conf.Column(c => c.Scope)
            .FilterSelect(c => c.Scope,
                          ui => ui.SelectAny().SelectItems(EnumHelper.GetSelectList(typeof(Scope))).ClientFiltering());

            // Value filter by specified price ranges
            conf.Column(c => c.Price).FilterValueNoUiBy((q, v) =>
                                                        v == 0 ? q.Where(x => x.Price > 5000 && x.Price < 15000) :
                                                        v == 1 ? q.Where(x => x.Price > 15000 && x.Price < 25000) :
                                                        v == 2 ? q.Where(x => x.Price > 25000 && x.Price < 35000) :
                                                        v == 3 ? q.Where(x => x.Price > 35000 && x.Price < 40000) :
                                                        v == 4 ? q.Where(x => x.Price > 40000 && x.Price < 50000) : q
                                                        );

            return(conf);
        }
Example #8
0
        public static Configurator <User, UserRow> ConfigureProjection(this Configurator <User, UserRow> conf)
        {
            // this is good example
            conf.ProjectDataWith(x =>
                                 x.Select(c => new UserRow() //<-- In case of using EntityFramework, this query will go to database
            {
                Id = c.Id,
                // do not use string.Format here as it doesnt have translation to SQL
                FullName  = c.FirstName + " " + c.LastName,
                Email     = c.Email,
                IsActive  = c.IsActive,
                ManagerId = c.Manager == null ? (int?)null : c.Manager.Id,

                // EF will convert that to left join
                ManagerName      = c.Manager == null ? null : c.Manager.FullName,
                RegistrationDate = c.RegistrationDate,

                // and this EF will convert to CROSS APPLY
                TotalOrder = c.Orders.Sum(d => d.Quantity * d.Price)
            }
                                          ));

            conf.Column(c => c.RegistrationDate).DataOnly(); //let's hide date column for convinience

            return(conf);
        }
Example #9
0
        /*
         * Table is operating on 2 classes -
         * Source data (here it is Toy type) is your DB/raw data type
         * Table data (here it is Row type) is our table row ViewModel
         *
         * For sure you can use Configurator<Toy,Toy> but in practice
         * displayed data differs from source data in 80% of cases
         */
        public static Configurator <Toy, Row> Basic(this Configurator <Toy, Row> conf)
        {
            /*
             * Use .MappedFrom to map data from columns in source data type
             */

            conf.Column(c => c.Name).MappedFrom(c => c.ToyName);
            conf.Column(c => c.ResponsibleUserName).MappedFrom(c => c.ResponsibleUser.FirstName + " " + c.ResponsibleUser.LastName);
            conf.Column(c => c.ResponsibleUserId).MappedFrom(c => c.ResponsibleUser.Id);
            conf.Column(c => c.Preorders).MappedFrom(c => c.PreordersCount);
            conf.Column(c => c.TypeOfToy).MappedFrom(c => c.GroupType);

            /*
             * All the columns can be reference by them RawName that corresponds to C# proprty name
             * No columns numeric IDs
             * Event in client side columns are referenced by names
             * Columns order stays same as declared in C# Table data class
             * So, to move column just move property in Table data C# class source up or down and
             * rebuild your project
             */

            /*
             * Basic tutorial is not about cells templating, but lets add template for date columns
             * Just make your eyes not bleed
             */
            conf.Column(c => c.CreatedDate).FormatDateWithDateformatJs("dd mmm yyyy");
            conf.Column(c => c.LastSoldDate).FormatDateWithDateformatJs("dd mmm yyyy");
            return(conf);
        }
        // Our table configuration method
        public static Configurator <User, UserRow> Configure(this Configurator <User, UserRow> conf)
        {
            // Let's hide UserRow.Id column just in case

            conf.Column(c => c.Id).DataOnly();
//         |                    |
//         |                    |
//         ----------------------
//              ^-- That's how we select columns for configuration
//                  Use .Column(lambda poiting to TRow property)

            // Let's also specify some titles here
            conf.Column(c => c.UserType).Title("Type");
            conf.Column(c => c.RegistrationDate).Title("Registered at");
            conf.Column(c => c.IsActive).Title("Active?");

            return(conf);
        }
        public static Configurator <Contract, ContractRow> ConfigureRangeFilters(this Configurator <Contract, ContractRow> conf)
        {
            conf.Table();
            conf.Column(c => c.Id).DataOnly();

            // Simple server filtering with default values
            conf.Column(c => c.Price).FilterRange(c => c.Price, ui => ui.RangeDefault(5000, 12000));

            // Filter delegate for tax filter
            conf.Column(c => c.Tax).FilterRange(c => c.Tax).Value(ExtractTaxRange);

            // Date range filters
            conf.Column(c => c.StartDate).FilterRange(c => c.StartDate).CompareOnlyDates();
            conf.Column(c => c.EndDate).FilterRangeNoUi(c => c.StartDate).CompareOnlyDates();


            return(conf);
        }
Example #12
0
        public static Configurator <Address, AddressRow> Configure(this Configurator <Address, AddressRow> configurator)
        {
            configurator.DefaultTable();

            configurator.PrimaryKey(row => row.Id);

            configurator.OrderFallback(address => address.Id);

            configurator.Column(row => row.Id).DataOnly();

            return(configurator);
        }
        public static Configurator <Contract, ContractRow> ConfigureValueFilters(this Configurator <Contract, ContractRow> conf)
        {
            conf.Table();
            conf.Column(c => c.Id).DataOnly();

            // Simple server filtering
            conf.Column(c => c.Title).FilterValue(c => c.Title);

            // Server configuration in order to continue configure filter
            // in cshtml
            conf.Column(c => c.Supplier).FilterValueNoUi(c => c.Supplier);

            // Value filter overriden by filtering delegate
            conf.Column(c => c.Price).FilterValueNoUi(c => c.Price)
            .By((q, v) => q.Where(x => x.Price < v));

            // Exactly the same as above
            conf.Column(c => c.Price).FilterValueNoUiBy((q, v) => q.Where(x => x.Price < v));

            // Overriden value extractor
            conf.Column(c => c.Tax)
            .FilterValueBy((q, v) => q.Where(x => x.Tax > v))
            .Value(q =>
            {
                if (!q.Filterings.ContainsKey("Tax"))
                {
                    return(FilterTuple.None <double?>());
                }
                var f = q.Filterings["Tax"];
                if (string.IsNullOrEmpty(f))
                {
                    return(FilterTuple.None <double?>());
                }
                var d = ValueConverter.Convert <double>(f);
                if (d > 10)
                {
                    d = d / 100;
                }
                return(((double?)d).ToFilterTuple());
            });

            // Automatic datepickers demo
            conf.Column(c => c.StartDate).FilterValue(c => c.StartDate).CompareOnlyDates();
            conf.Column(c => c.EndDate).FilterValueNoUi(c => c.StartDate).CompareOnlyDates();

            return(conf);
        }
Example #14
0
 public static Configurator <RoutePoint, RoutePointRow> Configure(
     this Configurator <RoutePoint, RoutePointRow> conf)
 {
     conf.DefaultTable();
     conf.Column(x => x.StationId).DataOnly();
     conf.PrimaryKey(x => new { x.RouteId, x.StationOrder });
     conf.ProjectDataWith(x => x.Select(rp => new RoutePointRow()
     {
         RouteId      = rp.RouteId,
         StationOrder = rp.StationOrder,
         StationId    = rp.StationId,
         StationName  = rp.Station.StationName
     }));
     return(conf);
 }
Example #15
0
        public static Configurator <Toy, Row> HideoutAndResponseInfo(this Configurator <Toy, Row> conf)
        {
            conf.RedirectingFilters();
            conf.Column(c => c.DeliveryDelay).DataOnly();
            conf.Column(c => c.Id).DataOnly();
            conf.Column(c => c.ResponsibleUserName).DataOnly(false);
            conf.Column(c => c.ItemsWasInitially).DataOnly();
            conf.Column(c => c.CreatedDate).DataOnly(false);
            conf.Column(c => c.LastSoldDate).DataOnly(false);

            conf.HideoutMenu(c => c.IncludeAll()
                             .Except(a => a.Id)
                             .Except(a => a.ResponsibleUserId)
                             .Except(a => a.ItemsLeft)
                             .Except(a => a.DeliveryDelay)
                             .Except(a => a.ItemsWasInitially)

                             , ui => ui.PlaceAt("lt"));

            conf.Column(c => c.TypeOfToy).Orderable(c => c.GroupType).Hide();
            conf.Column(c => c.Preorders).Orderable(c => c.GroupType).Hide();

            conf.ResponseInfo(ui => ui.PlaceAt("lb"), "lb");
            conf.ResponseInfo(
                ui => ui.PlaceAt("rb")
                .ClientTemplate(tpl =>
                                tpl.Returns(v => v.Tag("span")
                                            .Content("Filtered out:")
                                            .After(t => t.Tag("strong").Content("{FilteredOut}")))),
                rdi => new TutorialResponseInfo()
            {
                FilteredOut = rdi.Source.Count() - rdi.Filtered.Count()
            },
                "rb"
                );

            conf.Totals(totals =>
            {
                totals.AddTotalFormat(c => c.ItemsLeft, c => c.Source.Select(v => v.ItemsLeft).DefaultIfEmpty(0).Sum(), "{v} pcs.");
                totals.AddTotalTemplate(c => c.Id, c => c.Source.Select(v => v.Id).DefaultIfEmpty(0).Max(),
                                        c => c.EmptyIfNotPresentSelf().Returns(v => v.Tag("strong").Attr("class", "text-center").Content("Max ID: {@}")));
                totals.AddTotal(c => c.Price, c => c.Source.Select(v => v.Price).DefaultIfEmpty(0).Average(), "function(v) { return 'Avg. Price: $' + parseFloat(v).toFixed(2); }");
            });
            return(conf);
        }
Example #16
0
 public static Configurator <Employee, EmployeeRow> ConfigureTrainsStaff(this Configurator <Employee, EmployeeRow> conf)
 {
     conf.DefaultTable();
     conf.PrimaryKey(x => x.UserId);
     conf.Column(x => x.UserId).DataOnly();
     conf.NotAColumn(x => x.Login);
     conf.ProjectDataWith(e => from employee in e
                          select new EmployeeRow()
     {
         UserId   = employee.UserId,
         TrainId  = employee.TrainId,
         Position = employee.Position,
         Age      = employee.Age,
         Name     = employee.Name,
         Phone    = employee.Phone
     });
     return(conf);
 }
        public static Configurator <Toy, Row> ProjectionTitlesAndDataOnly(this Configurator <Toy, Row> conf)
        {
            /*
             * By default, Lattice is smart enough to map your data automatically
             * But for some cases passing projection (e.g. to EntityFramework)
             * can improve performance
             * And it is easier to track mappings from single place instead of
             * batches of .MappedFrom calls
             */
            conf.ProjectDataWith(c => c.Select(q => new Row()
            {
                Id                  = q.Id,
                Price               = q.Price,
                CreatedDate         = q.CreatedDate,
                TypeOfToy           = (ToyType)q.GroupType,
                Name                = q.ToyName,
                IsPaid              = q.Paid,
                ItemsLeft           = q.ItemsLeft,
                ItemsSold           = q.ItemsSold,
                Preorders           = q.PreordersCount ?? 0,
                LastSoldDate        = q.LastSoldDate,
                DeliveryDelay       = q.DeliveryDelay,
                ResponsibleUserId   = q.ResponsibleUser.Id,
                ResponsibleUserName = q.ResponsibleUser.FirstName + " " + q.ResponsibleUser.LastName,
                State               = (State)q.StateCode,
                PreviousState       = q.PreviousStateCode,
                SupplierAddress     = q.SupplierAddress
            }));

            conf.Column(c => c.TypeOfToy).Title("Class");
            conf.Column(c => c.ItemsSold).Title("Sold");
            conf.Column(c => c.ItemsWasInitially).Title("Initial");
            conf.Column(c => c.IsPaid).Title("Paid");
            conf.Column(c => c.CreatedDate).Title("Created");
            conf.Column(c => c.LastSoldDate).Title("Last sell");
            conf.Column(c => c.ResponsibleUserName).Title("Responsible");
            conf.Column(c => c.SupplierAddress).Title("Supp. Address");
            conf.PrimaryKey(c => c.Include(v => v.Id));

            /*
             * .DataOnly columns are passed to clien-side but are not displayed
             * Their purpose to be used in client-side per-row calculations
             * They present in client local storage and you can retrieve them e.g.
             * while templating cell, but they will never display
             */
            conf.Column(c => c.ItemsLeft).DataOnly();
            conf.Column(c => c.ResponsibleUserId).DataOnly();
            conf.Column(c => c.SupplierAddress).DataOnly(); // we hide it because it is long

            /*
             * We didnt use .Basec here, so I have to repeat dates displaying configuration
             */
            conf.Column(c => c.CreatedDate).FormatDateWithDateformatJs("dd mmm yyyy");
            conf.Column(c => c.LastSoldDate).FormatDateWithDateformatJs("dd mmm yyyy");
            return(conf);
        }
 private IConfigurator GetToc(string tutorialId)
 {
     var conf = new Configurator<TutorialEntry,TocEntryViewModel>();
     conf.Hierarchy();
     conf.ProjectDataWith(c => c.OrderBy(x=>x.Order).Select(x => new TocEntryViewModel()
     {
         IsExpanded = true,
         IsVisible = true,
         ChildrenCount = x.SubTutorials.Count,
         Description = x.Description,
         Link =
             Url.Action("Tutorial",
                 new { tutorialId = x.Namespace.Replace("Reinforced.Lattice.Book.WebApp.App_Data.", "").Replace(".", "_") }),
         Text = x.FriendlyName,
         ParentKey = x.Parent == null ? null : x.Parent.Namespace,
         RootKey = x.Namespace,
         IsSelected = x.Namespace.EndsWith(tutorialId)
     }));
     conf.Column(c=>c.Link).DataOnly();
     conf.Column(c=>c.Description).DataOnly();
     //conf.Column(c=>c.Order).OrderableUi(c=>c.UseClientOrdering().DefaultOrdering(Ordering.Ascending)).DataOnly();
     conf.Prefetch(TutorialsList.LinearTutorialList.OrderBy(c=>c.Order));
     conf.Column(c=>c.Text).FilterValueUi(ui=>ui.ClientFiltering().Placeholder("Search documentation...").Inputdelay(10));
     return conf;
 }
Example #19
0
        public static Configurator <Toy, Row> Filtering(this Configurator <Toy, Row> conf)
        {
            conf.ClientPagination();
            conf.LoadImmediately(true);
            conf
            .DatePicker(new DatepickerOptions(     // set up functions for 3rd party datepickers
                            "createDatePicker",
                            "putDateToDatepicker",
                            "getDateFromDatepicker",
                            "destroyDatepicker"
                            ))
            .AppendEmptyFilters()                  // tell table to draw empty filters for columns without filters
                                                   // it is needed when using table-look-like templating
            ;

            conf.Column(c => c.Price).FilterRange(c => c.Price, ui => ui.Placeholders("< price", "> price"));

            conf.Column(c => c.Preorders).Title("Preorders (pure client)").FilterRangeUi(ui => ui.Placeholders("Min. Id", "Max. Id").Inputdelay(50).ClientFiltering());

            conf.Column(c => c.TypeOfToy).Title("Type (client, multiple)")
            .FilterMultiSelect(c => c.GroupType, ui => ui.SelectItems(EnumHelper.GetSelectList(typeof(ToyType))).ClientFiltering());

            conf.Column(c => c.IsPaid).Title("Paid (server filter)").FilterBoolean(c => c.Paid, "Paid", "Unpaid", "Any");

            conf.Column(c => c.CreatedDate).FilterValue(c => c.CreatedDate); // datepicker will be added automatically

            /*
             * Ok, here should be few words said
             * When you specify source column and it is nullable then things become complicated,
             * so you can encounter null-related errors from time to time
             *
             * In this case you should alter column filtering expression with null-coalescing (??) operator or with .GetValueOrDefault
             * to make it suitable for query provider.
             * Otherwise, Lattice will alter your column expression (if it is nullable) with .Value property. It may not work for all
             * query providers, so if you dont like this behavior use .By call and handle null values by yourself
             */
            conf.Column(c => c.LastSoldDate).FilterRange(c => c.LastSoldDate.GetValueOrDefault(),
                                                         ui => ui.RangeDefault(DateTime.Now.AddDays(-50), DateTime.Now)); // filter by range of dates with default values


            /*
             * We hide unrelated columns just for convinence
             */
            conf.Column(c => c.DeliveryDelay).DataOnly();
            conf.Column(c => c.Id).DataOnly();
            conf.Column(c => c.ResponsibleUserName).DataOnly();
            conf.Column(c => c.ItemsWasInitially).DataOnly();
            conf.Column(c => c.PreviousState).Title("Prev. state").FilterSelect(c => c.PreviousStateCode, ui => ui.SelectNotPresent().SelectItems(EnumHelper.GetSelectList(typeof(State))).ClientFiltering());
            return(conf);
        }
        public static Configurator <Contract, ContractRow> ConfigureMultiSelectFilters(this Configurator <Contract, ContractRow> conf)
        {
            conf.Table();
            conf.Column(c => c.Id).DataOnly();

            // Simple select filter with default values
            conf.Column(c => c.Rating)
            .FilterMultiSelect(c => c.Rating, ui => ui.SelectAny()
                               .SelectItems(new UiListItem[]
            {
                new UiListItem()
                {
                    Text = "*", Value = "1"
                },
                new UiListItem()
                {
                    Text = "**", Value = "2", Selected = true
                },
                new UiListItem()
                {
                    Text = "***", Value = "3", Selected = true
                },
                new UiListItem()
                {
                    Text = "****", Value = "4", Selected = true
                },
                new UiListItem()
                {
                    Text = "*****", Value = "5"
                },
            }));

            // Select filter for enumeration with client filtering
            conf.Column(c => c.Scope)
            .FilterMultiSelect(c => c.Scope,
                               ui => ui.SelectAny().SelectItems(EnumHelper.GetSelectList(typeof(Scope))).ClientFiltering());

            // Value filter by specified price ranges
            conf.Column(c => c.Price)
            .FilterMultiSelectNoUiBy((q, v) =>
            {
                if (!v.Any())
                {
                    return(q);
                }
                var _5_15  = v.Contains(0);
                var _15_25 = v.Contains(1);
                var _25_35 = v.Contains(2);
                var _35_40 = v.Contains(3);
                var _40_50 = v.Contains(4);

                return(q.Where(c =>
                               (_5_15 && (c.Price > 5000 && c.Price < 15000)) ||
                               (_15_25 && (c.Price >= 15000 && c.Price <= 25000)) ||
                               (_25_35 && (c.Price >= 25000 && c.Price <= 35000)) ||
                               (_35_40 && (c.Price >= 35000 && c.Price <= 40000)) ||
                               (_40_50 && (c.Price >= 40000 && c.Price <= 50000))
                               ));
            });

            return(conf);
        }
Example #21
0
        public static Configurator <Contract, ContractRow> ConfigureMixedFilters(this Configurator <Contract, ContractRow> conf)
        {
            conf.Table();
            conf.Column(c => c.Id).DataOnly();

            // Simple server filtering
            conf.Column(c => c.Title).FilterValue(c => c.Title);

            // Server configuration in order to continue configure filter
            // in cshtml
            conf.Column(c => c.Supplier).FilterValueNoUi(c => c.Supplier);

            // Simple server filtering
            conf.Column(c => c.Price).FilterRange(c => c.Price);

            // Simple select filter
            conf.Column(c => c.Rating)
            .FilterSelect(c => c.Rating, ui => ui.SelectAny()
                          .SelectItems(new UiListItem[]
            {
                new UiListItem()
                {
                    Text = "*", Value = "1"
                },
                new UiListItem()
                {
                    Text = "**", Value = "2"
                },
                new UiListItem()
                {
                    Text = "***", Value = "3"
                },
                new UiListItem()
                {
                    Text = "****", Value = "4"
                },
                new UiListItem()
                {
                    Text = "*****", Value = "5"
                },
            })
                          .ClientFiltering() // with client filtering!
                          );

            // Select filter for enumeration with client filtering
            conf.Column(c => c.Scope)
            .FilterSelect(c => c.Scope,
                          ui => ui.SelectAny().SelectItems(EnumHelper.GetSelectList(typeof(Scope))).ClientFiltering());

            // Overriden value extractor
            conf.Column(c => c.Tax)
            .FilterValueBy((q, v) => q.Where(x => x.Tax > v))
            .Value(q =>
            {
                if (!q.Filterings.ContainsKey("Tax"))
                {
                    return(FilterTuple.None <double?>());
                }
                var f = q.Filterings["Tax"];
                if (string.IsNullOrEmpty(f))
                {
                    return(FilterTuple.None <double?>());
                }
                var d = ValueConverter.Convert <double>(f);
                if (d > 10)
                {
                    d = d / 100;
                }
                return(((double?)d).ToFilterTuple());
            });

            // Automatic datepickers demo
            conf.Column(c => c.StartDate).FilterRange(c => c.StartDate).CompareOnlyDates();

            conf.Column(c => c.EndDate).FilterValueNoUi(c => c.StartDate).CompareOnlyDates();

            return(conf);
        }
Example #22
0
        public static Configurator <Toy, Row> Editor(this Configurator <Toy, Row> conf)
        {
            conf.ClientPagination();
            conf
            .DatePicker(new DatepickerOptions(     // set up functions for 3rd party datepickers
                            "createDatePicker",
                            "putDateToDatepicker",
                            "getDateFromDatepicker",
                            "destroyDatepicker"
                            ));

            conf.LoadingOverlap(ui => ui.Overlap());
            conf.LoadImmediately(true);
            conf.Column(c => c.SupplierAddress).DataOnly(false);
            conf.Column(c => c.ItemsSold).DataOnly();
            conf.Column(c => c.DeliveryDelay).DataOnly();
            conf.Column(c => c.ItemsWasInitially).DataOnly();
            conf.Column(c => c.Preorders).DataOnly();
            conf.Column(c => c.LastSoldDate).DataOnly();
            conf.Column(c => c.ResponsibleUserName).DataOnly();
            conf.Column(c => c.Price).OrderableUi(ui => ui.DefaultOrdering(Ordering.Neutral));
            conf.Column(c => c.Id).Orderable(c => c.Id, ui => ui.DefaultOrdering(Ordering.Descending));


            conf.AdjustmentTemplates("updatedRow", "updatedCell", "addedRow");

            conf.Column(c => c.Name)
            .Template(t => t.Returns(v => v.Tag("span")
                                     .Attr("style", "background-color:aliceblue")
                                     .Data("editcell", "true").Content("{Name}")
                                     ))
            .EditPlainText();
            conf.Column(c => c.CreatedDate)
            .Template(t => t.Returns(
                          v => v.Tag("div").Content(
                              c => c.Tag("span").Content("`dateFormat({CreatedDate},'dd mmm yyyy',false)`").EditPencil())))
            .EditPlainText()
            ;
            conf.Column(c => c.Price)
            .Template(t => t.Returns(
                          v => v.Tag("div").Content(
                              c => c.Tag("span").Content("{Price}").EditPencil())))
            .EditPlainText(t => t.TemplateId("plainTextEditorAlternate"))
            ;
            conf.Column(c => c.IsPaid)
            .Template(t =>
            {
                t.Returns(v => v.Tag("div").Content(c => c.Tag("span").Content("`{IsPaid}.toString() + ({^IsUpdated}?'edited':'')`").EditPencil()));
            })
            .EditCheck()
            ;
            conf.Column(c => c.SupplierAddress)
            .Template(t => t.Returns(
                          v => v.Tag("div").Content(
                              c => c.Tag("span").Content("{SupplierAddress}").EditPencil())))
            .EditMemo(c => c.Size(3, 10))
            ;

            conf.Column(c => c.TypeOfToy)
            .FormatEnumWithDisplayAttribute((tpl, v) => tpl.Content(v.Text).EditPencil())
            .EditSelectList(c => c.Items(EnumHelper.GetSelectList(typeof(ToyType))).WithEmptyElement("---Select---", false))
            ;
            return(conf);
        }