MVC Grid Column Renderer Multiple Column Values

  1. #1

    MVC Grid Column Renderer Multiple Column Values

    Can anyone help

    I am trying to add a column type that is a hyperlink. I would like to control how this is rendered in JS.

    Html.X().Column().DataIndex("Id").Renderer("MyFunc ")

    This is close to what I need, but the limitation with this is the DataIndex column is passed only. I would like two pass 2 column values. There are a number of ways to do this with the various toolbar buttons and command buttons but none seem to let me produce a hyperlink. Ideally I am after a custom listener to pass what columns I like this will give me the greatest control using JS.

    Thanks,
  2. #2
    Please let me know whether the following example helps you

    1 - View
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <script type="text/javascript">
            var mergeAddressAndName = function (value, record) {
                return Ext.net.StringUtils.format('<a href="https://www.google.com.br/search?q={0}+{1}"><b>Search {0}+{1}</b></a>', record.data.Name, record.data.Address);
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:GridPanel ID="GridPanel1" Title="Records" runat="server">
            <Store>
                <ext:Store runat="server" ID="Store2">
                    <Proxy>
                        <ext:AjaxProxy Url="/Example/LoadFakeRecords/">
                            <ActionMethods Read="POST" />
                            <Reader>
                                <ext:JsonReader Root="data" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
                    <Model>
                        <ext:Model ID="Model2" runat="server">
                            <Fields>
                                <ext:ModelField Name="ID" Type="String" />
                                <ext:ModelField Name="Name" Type="String" />
                                <ext:ModelField Name="Address" Type="String" />
                                <ext:ModelField Name="NameAndAddress">
                                    <Convert Fn="mergeAddressAndName" />
                                </ext:ModelField>
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" />
                    <ext:Column ID="Column3" runat="server" Text="Name" DataIndex="Name" />
                    <ext:Column ID="Column4" runat="server" Text="Address" DataIndex="Address" />
                    <ext:Column ID="Column2" runat="server" Text="Name + Address" DataIndex="NameAndAddress" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </body>
    </html>
    2 - Controller

    public class ExampleController : System.Web.Mvc.Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    
        public StoreResult LoadFakeRecords()
        {
    
            List<Person> lst = new List<Person>();
    
            for (int index = 0; index < 15; index++)
            {
                lst.Add(new Person
                {
                    ID = index,
                    Name = "Name" + index,
                    Address = "Address" + index,
                });
            }
    
            return new StoreResult(lst, lst.Count());
        }
    }
    3 - Utility
    public class Person
    {
        public int ID { get; set; }
    
        public string Name { get; set; }
    
        public string Address { get; set; }
    }

Similar Threads

  1. [CLOSED] Grid Column Renderer funcation called twice
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 15
    Last Post: Jan 09, 2012, 9:55 PM
  2. Grid Column Renderer
    By karthik.arian03 in forum 1.x Help
    Replies: 8
    Last Post: Feb 11, 2011, 6:34 AM
  3. [CLOSED] number renderer in grid column
    By Vasudhaika in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 05, 2010, 10:01 AM
  4. [CLOSED] Tooltip / Renderer for Grid Header Column
    By csharpdev in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 02, 2010, 9:16 AM
  5. [CLOSED] Grid Column Renderer for Currency £
    By CMA in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 07, 2010, 4:52 PM

Posting Permissions