ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Show a div conditionally within the client format
Title:
B
I
{code}
?
I have the following column in an awesome grid where I want to show only one div based on the property value. How do I accomplish this? .Custom("persistFilter")) .Columns( new Column { ClientFormat = "<div><a href='Edit?siteId=" + Model.SiteId + "&&mechanismID=" + Model.MechanismId + "&&indicatorId=.(IndicatorId)' class='glyphicon glyphicon-pencil')' style='display:inline-block'></a>" + //show this if .(isIndicatorType==true) "<a href='ModalityList?siteId=.(SiteId)&&mechanismId=.(MechanismId)&&indicatorId=.(IndicatorId)' class='glyphicon glyphicon-th-list')' style='display:inline-block'></a>" + ////show this if .(isIndicatorType==false) CssClass = "o-glnon", Width = 50, Name = "View Action", }, Could you please tell me how to access within the func1 a property that's not in the grid but it's on the ViewModel that this View is using. something like @Model.ParentSiteId?
Save Changes
Cancel
riya
asked at 19 Dec 2023
Answers
B
I
{code}
?
You can use a js function to render the cell content using `ClientFormatFunc`, see demo here: https://demo.aspnetawesome.com/GridDemo/CustomFormat here's a short example: new Column { ClientFormatFunc = "func1", ... and the js function: function func1(model) { console.log(model); if (isIndicatorType) return "condition is true; " + model.SiteId + " " + model.IndicatorId; return "<b>not true</b>"; } --- To use a ViewModel Property inside the js function, if `func1` is in the same view you can simply render it inside: function func1(model) { var v1 = '@Model.ParentSiteId' ; otherwise you could call `ClientFormatFunc = "funcThatReturnsFunc1('" + Model.ParentSiteId + "')"`, and the function would look like this: function funcThatReturnsFunc1(parentSiteId) { return function(model) { console.log(model, parentSiteId); return "true or false"; } }
Save Changes
Cancel
Omu
answered at 19 Dec 2023
Thanks for your fast response.
at 20 Dec 2023
riya
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