[CLOSED] GridPanel Column Renderer(Get value from custom class's method)

  1. #1

    [CLOSED] GridPanel Column Renderer(Get value from custom class's method)

    Hi,

    I searched and find a lot of answer like my questions but i can't solved my problem.
    i want call my custom method when gridpanel column renderer time.

    My Codes;


    <script>
    var PersonName = function(value, metadata, record) {
                HesapIslemleri.GetPersonName(record.data.ID);
            }
    </script>
    
    
      <ext:GridPanel ID="gpMizanRapor" runat="server" ButtonAlign="Left">
                            <Store>
                                <ext:Store ID="stoHesapList" runat="server" PageSize="50">
                                    <Model>
                                        <ext:Model ID="Model4" runat="server">
                                            <Fields>
                                              
                                                <ext:ModelField Name="KayitPersonel" Type="String" />
                                             
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
     <ColumnModel ID="ColumnModel1" runat="server">
                                <Columns>
                                                   <ext:Column ID="Column1" runat="server" DataIndex="KayitPersonel" Width="500" Text="Kay?t Eden">
                                        <Renderer Fn="PersonName" />
                                    
                                    </ext:Column>
                                </Columns>
                            </ColumnModel>
    </ext:GridPanel>
    
    
    
        [DirectMethod(Namespace = "HesapIslemleri")]
        public void GetPersonName(object ID)
        {
            var id = Convert.ToInt32(ID);
    
    var personname=MyClass.GetPersonNameFromByID(id);
    
    this.gpMizanRapor.GetStore().GetById(id).Set("KayitPersonel", personname); // It's doesnt work
    this.gpMizanRapor.GetStore().GetById(id).Commit();
    //gpMizanRapor.GetStore().CommitChanges()
    }
    Last edited by Daniil; Jan 16, 2015 at 9:23 AM. Reason: [CLOSED]
  2. #2
    Hi @ddeniz,

    Please wrap the code in [CODE] tags, see #3:
    Forum Guidelines For Posting New Topics
  3. #3
    Hello,

    I see your main issue here is the same issue more people had in the past: calling a directMethod off a renderer. This does not actually works. At least when I needed something like this, what I had to do is load the data thru the store and then from javascript renderer function, manipulate it.

    In other words:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HesapIslemeri.aspx.cs" Inherits="ExtNetPlayground.HesapIslemeri" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <ext:ResourceManager runat="server" />
        <script type="text/javascript">
            var pageLoading = true;
            var PersonName = function (value, metadata, record) {
                // Avoid re-rendering uselessly
                if (pageLoading && id.column.componentLayoutCounter != 2) {
                    return "" // or return value
                };
    
                // modify your value as you feel fit
                var retData = "<i>" + value + "</i>";
    
                return retData;
            }
        </script>
        <script runat="server">
            string[] namelist = { "Joe", "Moe", "Zoe" };
            string GetPersonNameFromByID(int id)
            {
                return namelist[id];
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
                stoHesapList.DataSource = new object[]
                {
                    new { id = 1, KayitPersonel = GetPersonNameFromByID(1) },
                    new { id = 2, KayitPersonel = GetPersonNameFromByID(2) },
                    new { id = 3, KayitPersonel = GetPersonNameFromByID(3) }
                };
                stoHesapList.DataBind();
            }
            
            [DirectMethod]
            public string GetPersonName(object ID)
            {
                var id = Convert.ToInt32(ID);
    
                var personname = this.GetPersonNameFromByID(id);
    
                return personname;
            } 
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:GridPanel ID="gpMizanRapor" runat="server" ButtonAlign="Left">
                <Store>
                    <ext:Store ID="stoHesapList" runat="server" PageSize="50">
                        <Model>
                            <ext:Model ID="Model4" runat="server">
                                <Fields>
                                    <ext:ModelField Name="ID" Type="Int" />
                                    <ext:ModelField Name="KayitPersonel" Type="String" />
                                    <ext:ModelField Name="rawPersName" Type="String" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ID="Column1" runat="server" DataIndex="KayitPersonel" Width="500" Text="Kayıt Eden">
                            <Renderer Fn="PersonName" />
                        </ext:Column>
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </div>
        </form>
    </body>
    </html>
    But, most times these changes works just fine at data source build time (for example, if your GetPersonNameFromByID already returned a string as <i>NAME</i>. In that case, you will not need a renderer at all.

    Another option, if you want to avoid overloading your page, is to make a server-side pager, where each page you advance in the grid, data is re-loaded from server, keeping your local (browser/javascript) data at a minimum.
    For this option, what you need is this.

    Well, I hope something of this helps you in building your actual solution. In general, try to think how you could prepare your data before the grid starts to load.

Similar Threads

  1. Replies: 0
    Last Post: May 22, 2014, 12:06 PM
  2. [CLOSED] Custom parameter in grid column Renderer
    By alscg in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Dec 16, 2013, 3:01 AM
  3. [CLOSED] when gridpanel column apply renderer.format , renderer.fn not work
    By mis@adphk.com in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 12, 2013, 10:35 AM
  4. Replies: 1
    Last Post: Mar 06, 2013, 7:54 AM
  5. Replies: 4
    Last Post: Jul 15, 2010, 4:25 PM

Posting Permissions