joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
74 stars 55 forks source link

More action link in a column with valueexpression #28

Closed csabaantoni closed 8 years ago

csabaantoni commented 8 years ago

Hi!

I want to add a column to the grid with more than one action link with icons like in image. And links visibility depend on a property value.

How can I do it?

Is it possible?

Thanks!

gridactions

joeharrison714 commented 8 years ago

Sure you can. ValueExpression just returns a string of whatever you want to be in the column, so just build the HTML you want and return it. Here is an example of the column definition:

                    cols.Add("Actions").WithHtmlEncoding(false).WithValueExpression((p, c) =>
                    {
                        // here's how to get an action url
                        string url = c.UrlHelper.Action("action1", "test");

                        // build whatever html you want
                        StringBuilder sb = new StringBuilder();
                        sb.Append("<img src='action1.png' onclick='someFunction()'>");
                        sb.Append("<img src='action2.png' onclick='someFunction()'>");

                        // conditional html
                        if (p.Col4)
                        {
                            sb.Append("<img src='action3.png' onclick='someFunction()'>");
                        }

                        return sb.ToString();
                    });