PDA

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



ddeniz
Jan 12, 2015, 9:57 AM
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()
}

Daniil
Jan 12, 2015, 12:02 PM
Hi @ddeniz,

Please wrap the code in [CODE] tags, see #3:
Forum Guidelines For Posting New Topics (http://forums.ext.net/showthread.php?3440)

fabricio.murta
Jan 12, 2015, 1:43 PM
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 (http://examples2.ext.net/#/GridPanel/Paging_and_Sorting/Local_Paging_with_Remote_Data/).

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.