ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Grid Custom Filtering by bool column value
Title:
B
I
{code}
?
I have a grid that takes in data that is either true or false and if it is true converts it to "Yes" and if it is false converts it to "No" using the activeToText function. I was wondering since this is custom if there is a way to still add filtering to this? Meaning that the user can select Yes or No from a dropdown and the column will filter based on that. Html.Awe().Grid("ExampleGrid"). ... new Column { Bind = "CustomFormattingColumn", Header = "CustomFormattingColumn", ClientFormatFunc = "binaryToText", Width = 100 })) var activeToText = function(model, prop) { var activeString = model[prop] ? "Yes" : "No"; return '<div>' + activeString + '</div>'; }
Save Changes
Cancel
Soabdalla
asked 5 days ago
Answers
B
I
{code}
?
Yes, you can add filtering based the value of your bool column, 1) A simple way is using parent binding, as shown here https://demo.aspnetawesome.com/GridDemo Add a DropdownList or checkbox, toggle, but with the checkbox there's no option for showing both yes and no: @(Html.Awe().DropdownList( new () { Name = "ddIsActive", DataFunc = "getYesNoList" ClearBtn = true })) ... @(Html.Awe().Grid("Grid1") ... .Parent("ddIsActive", "isActive") and make use of the `isActive` parameter in the controller public IActionResult GetItems(GridParams g, bool? isActive) 2) Another way is using filter row: assuming the name of your entity is `Example`, so you have `GridModelBuilder<Example>` new Column {Bind = "IsActive"} .FltDropdownList(new DropdownListOpt() { Name = "IsActive", DataFunc = "getYesNoList", AutoSearch = false })) // instead of DataFunc Url can be used also and in the controller add to your filterBuilder: filterBuilder .Add(nameof(ExampleFilter.IsActive), new FilterRule<Example>() { Query = ent => ent.IsActive == filter.ent.Value }) in your `ExampleFilter` class make sure to have: public bool? IsActive { get; set; } <hr/> js function used by both methods, you could also use `Url` instead of `DataFunc` and have this list ( `KeyContent[]` ) returned by the server <script> function getYesNoList() { return [ { k: "true", c: "Yes" }, { k: "false", c: "No" } ]; } </script>
Save Changes
Cancel
Omu
answered 5 days ago
Got it. Thank you for this. I should have been more specific in my original post but what about if I wanted to use the .Mod(o => o.Filter(...)) extension on my grid column. Does similar logic seem to apply? I can't seem to find the demo that answers this so I apologize if it exists.
4 days ago
Soabdalla
if you have `FilterRow` mod on the Grid you can use `.Flt(awe helper)` extension on the column, or `.FltString`, `.FltDropdownList`, etc. the demo is here: https://demo.aspnetawesome.com/GridFilterRowServerSideData
4 days ago
Omu
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK