[CLOSED] [0.8.1] Link Renderer redirect to AjaxMethod Dynamic GridPanel

  1. #1

    [CLOSED] [0.8.1] Link Renderer redirect to AjaxMethod Dynamic GridPanel

    I'm creating a javascript function that show a grid column like a link, and that function redirects to an AjaxMethod that takes like a parameter the entire row where I clicked but doesn't work, I recieve an (object Object) in the AjaxMethod parameter.

    Here is the sample code.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        private RecordFieldType MappingType(Type type)
        {
            if (type == typeof(string))
            { return RecordFieldType.String; }
            else if (type == typeof(DateTime))
            { return RecordFieldType.Date; }
            else if (type == typeof(int))
            { return RecordFieldType.Int; }
            else if (type == typeof(double))
            { return RecordFieldType.Float; }
            else if (type == typeof(bool))
            { return RecordFieldType.Boolean; }
            return RecordFieldType.Auto;
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("StringColumn", typeof(string));
            dt.Columns.Add("DateTimeColumn", typeof(DateTime));
            dt.Columns.Add("IntColumn", typeof(int));
            dt.Columns.Add("DoubleColumn", typeof(double));
            dt.Columns.Add("BoolColumn", typeof(bool));
            DateTime now = DateTime.Now;
            for (int i = 1; i <= 10; i++)
            {
                dt.Rows.Add("s" + i, now.AddDays(i), i, i * 1.0, (i & 1) == 0);
            }
            JsonReader reader = new JsonReader();
            Store store = new Store { ID = "Store1", Reader = { reader } };
    
            GridPanel grid = new GridPanel { ID = "GridPanel1", AutoHeight = true, };
            grid.Controls.Add(store);
            grid.StoreID = store.ClientID;
    
            this.Form.Controls.Add(grid);
            foreach (System.Data.DataColumn column in dt.Columns)
            {
                reader.Fields.Add(column.ColumnName, this.MappingType(column.DataType));
                grid.ColumnModel.Columns.Add(new Column { Header = column.ColumnName, DataIndex = column.ColumnName, Width = 200 });
            }
            grid.ColumnModel.Columns[0].Renderer.Fn = "linkRenderer";
            store.DataSource = dt;
            store.DataBind();
        }
    
        [AjaxMethod]
        public void SayHello(string campo1)
        {
            string[] campos = campo1.Split(',');
        }
    
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">        
            .linkPleaseWait        
            {            
                color: Olive;        
            }    
        </style>
        
        <script type="text/javascript">
    
            var linkRenderer = function (value, meta, grid, record, rowIndex, store) {
                var field1 = store.data.items[record].json;
                debugger;
                return String.format('<a href="#" onclick="Coolite.AjaxMethods.SayHello(\'{1}\')" class="linkPleaseWait">{0}</a>', value, field1);
            };
            
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ScriptManager ID="ScriptManager1" runat="server">
            </ext:ScriptManager>
        </div>
        </form>
    </body>
    </html>
    Do you have any advice?

    Thanks....
    Last edited by Daniil; Sep 29, 2010 at 6:41 PM. Reason: [CLOSED]
  2. #2
    Hi cobiscorp,

    If I understood you properly a code should look like this:

    Example
    var linkRenderer = function(value, meta, grid, record, rowIndex, store) {
        var field1 = store.data.items[record].json;
        var s = '';
        for (var item in field1) {
            s += field1[item] + ",";
        }
        return String.format('<a href="#" onclick="Coolite.AjaxMethods.SayHello(\'{1}\')" class="linkPleaseWait">{0}</a>', value, s);
    };
  3. #3
    the solution above works fine, but I would like that the AjaxMethod recieves the parameter in Json format in order to apply this:

    Dictionary<string, string>[] selectedData = JSON.Deserialize<Dictionary<string, string>[]>(json);
    Where json is the parameter from the AjaxMethod (SayHello)..
    Something like this:

     [AjaxMethod]
        public void SayHello(SomeType  json)
        {
            Dictionary<string, string>[] selectedData = JSON.Deserialize<Dictionary<string, string>[]>(json);
        }
    How it could be done the javascript function (linkrenderer) in order to achieve that?
  4. #4
    I would suggest you this way:

    Example
    [AjaxMethod]
    public void SayHello(string campo1)
    {
        Dictionary<string, string> dict = JSON.Deserialize<Dictionary<string, string>>(campo1);
        Ext.Msg.Alert("", dict["DoubleColumn"]).Show();
    }
    
    ...
    
    <script type="text/javascript">
        var linkRenderer = function(value, metadata, record, rowIndex, colIndex, store) {
            return String.format("<a href='#' onclick='clickHandler(\"{0}\")' class='linkPleaseWait'>{1}</a>", record.id, value);
        }
    
        var clickHandler = function(recordId) {
            var json = GridPanel1.getStore().getById(recordId).json;
            Coolite.AjaxMethods.SayHello(Ext.encode(json));
        }
    </script>
    Please note the order of Renderer parameters. The one in your code is a little bit wrong.

Similar Threads

  1. Dynamic Gridpanel - Add Renderer - how to?
    By Tbaseflug in forum 1.x Help
    Replies: 2
    Last Post: Apr 02, 2012, 2:37 PM
  2. Replies: 18
    Last Post: Apr 14, 2010, 2:00 PM
  3. [CLOSED] Redirect Issue in AjaxMethod...
    By shahidmughal in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 12, 2010, 2:26 AM
  4. [CLOSED] Not able to redirect a page in AjaxMethod
    By Etisbew in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 25, 2009, 4:16 AM
  5. Renderer with link - load params for store
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Aug 14, 2009, 12:51 PM

Posting Permissions