PDA

View Full Version : [CLOSED] Getting the count of the records in the Grid after calling the store.LoadProxy();



Fahd
Aug 15, 2012, 8:43 PM
This is my previous post below:
http://forums.ext.net/showthread.php?20029-CLOSED-After-doing-a-Store1-DataBind()-how-could-I-find-the-count-of-how-many-items-are-in-the-Store&p=87352#post87352 (http://forums.ext.net/showthread.php?20029-CLOSED-After-doing-a-Store1-DataBind%28%29-how-could-I-find-the-count-of-how-many-items-are-in-the-Store&p=87352#post87352)

.aspx


<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>GridPanel with HtppHandler - Ext.NET Examples</title>
<script language="javascript" type="text/javascript">

JFunction fn = new JFunction()
{
Handler = "alert(records.length);",
Args = new string[] { "records", "operation", "success" }
};
Store store = this.GridPanel1.GetStore();
store.LoadProxy(new
{
callback = fn
});


</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager runat="server" />
<h1>
GridPanel with HtppHandler - Ext.NET Examples</h1>
<br />
<ext:GridPanel ID="GridPanel1" runat="server" Title="Employees" Frame="true" Height="200"
Width="600">
<Store>
<ext:Store ID="Store1" runat="server">
<Proxy>
<ext:AjaxProxy Url="../Handlers/GetHandler.ashx">
<ActionMethods Read="GET" />
<Reader>
<ext:JsonReader Root="Data" TotalProperty="TotalRecords" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Common" />
<ext:ModelField Name="Botanical" />
<ext:ModelField Name="Light" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Common Name" DataIndex="Common" Sortable="true"
Flex="1" />
<ext:Column runat="server" Text="Botanical" DataIndex="Botanical" Width="200" />
<ext:Column runat="server" Text="Light" DataIndex="Light" Width="100" />
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>



GetHandler.ashx.cs


using System.Collections.Generic;
using System.Web;
using Ext.Net;

namespace Web.Handlers
{
public class GetHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
context.Response.Write(JSON.Serialize(Plant.TestDa ta));
}

public bool IsReusable
{
get { return false; }
}

public class Plant
{
public Plant(string light, string botanical, string common)
{
Light = light;
Botanical = botanical;
Common = common;
}

public Plant() { }

public string Common { get; set; }
public string Botanical { get; set; }
public string Light { get; set; }

public static List<Plant> TestData
{
get
{
var items = new List<Plant>();

var plant1 = new Plant { Common = "Bloodroot", Botanical = "Sanguinaria canadensis", Light = "Mostly Shady"};
items.Add(plant1);

var plant2 = new Plant { Common = "Marsh Marigold", Botanical = "Caltha palustris", Light = "Mostly Sunny" };
items.Add(plant2);

var plant3 = new Plant { Common = "Cowslip", Botanical = "Sanguinaria canadensis", Light = "Sun or Shade" };
items.Add(plant3);
return items;
}
}
}

}

}

Daniil
Aug 16, 2012, 6:38 AM
Hi,

It looks to be C# code, not JavaScript.



<script language="javascript" type="text/javascript">

JFunction fn = new JFunction()
{
Handler = "alert(records.length);",
Args = new string[] { "records", "operation", "success" }
};
Store store = this.GridPanel1.GetStore();
store.LoadProxy(new
{
callback = fn
});
</script>


Also the problem is unclear. Please provide more details.

Fahd
Aug 16, 2012, 3:32 PM
I have updated my sample, but I can't get the Javascript funtion to fire.

I expect it to fire my Javascript function, 'NoOfRecords' showing my the # of records.

When I click the Button, "Load Proxy"

works


Handler = "alert(records.length);"


does NOT work


Fn = "NoOfRecords(records.length);",


.aspx


<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>GridPanel with HtppHandler - Ext.NET Examples</title>
<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
Store1.Proxy.Add(new AjaxProxy
{
NoCache = true,
Json = true,
ActionMethods = { Read = HttpMethod.GET },
Reader = { new JsonReader { Root = "Data", TotalProperty = "TotalRecords" } },
Url = "../Handlers/GetHandler.ashx"
});
}

[DirectMethod]
public void LoadProxy(object sender, DirectEventArgs e)
{
var fn = new JFunction()
{
//Handler = "alert(records.length);",
Fn = "NoOfRecords(records.length);",
Args = new [] { "records", "operation", "success" }
};

var store = GridPanel1.GetStore();
store.LoadProxy(new
{
callback = fn
});
}

</script>

<script language="javascript" type="text/javascript">

var NoOfRecords = function(length){
debugger;
Ext.Msg.notify("Number of Records", "Rows: " + length);
}

</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager runat="server" />
<h1>
GridPanel with HtppHandler - Ext.NET Examples</h1>
<br />
<ext:GridPanel ID="GridPanel1" runat="server" Title="Employees" Frame="true" Height="200"
Width="600">
<Store>
<ext:Store ID="Store1" runat="server" AutoDataBind="false" AutoLoad="false">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Common" />
<ext:ModelField Name="Botanical" />
<ext:ModelField Name="Light" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Common Name" DataIndex="Common" Sortable="true"
Flex="1" />
<ext:Column runat="server" Text="Botanical" DataIndex="Botanical" Width="200" />
<ext:Column runat="server" Text="Light" DataIndex="Light" Width="100" />
</Columns>
</ColumnModel>
</ext:GridPanel>
<br />
<ext:Button ID="Button1" runat="server" Text="Call Proxy" OnDirectClick="LoadProxy" />
</form>
</body>
</html>



Hi,

It looks to be C# code, not JavaScript.



Also the problem is unclear. Please provide more details.

Daniil
Aug 16, 2012, 3:55 PM
Fn expects a function name or a full function definition.

Fn="someFunctionName"
or
Fn="function () { alert('Hello!'); }"

Fahd
Aug 16, 2012, 4:53 PM
Got it. thanks...


Fn expects a function name or a full function definition.

Fn="someFunctionName"
or
Fn="function () { alert('Hello!'); }"