PDA

View Full Version : [CLOSED] Ext .NET Override method best practice?



softmachine2011
Jun 19, 2012, 8:17 AM
Hi,

I need to override createSortFunction method in Ext.util.Sorter.

Dummy example:


Ext.util.Sorter.override({
constructor: function () {
debugger;
alert('1,2,3...');
},

createSortFunction: function (sorterFn) {
debugger;
var me = this,
property = me.property,
direction = me.direction || "ASC",
modifier = direction.toUpperCase() == "DESC" ? -1 : 1;

alert('croak!');
return function (o1, o2) {
return modifier * sorterFn.call(me, o1, o2);
};
}
});


I tried calling the override in different events of the application, but can not find the event before rendering ExtJS components.

In Ext.NET1.x, if applied in the Ext.onReady worked well.

The idea is not having to replicate the call on all screens BeforeRender.

Is there any way to replicate the behavior Ext.NET 2.x?

Thanks,

Daniil
Jun 19, 2012, 12:50 PM
Hi,

The following appear to be working. The overrode constructor and createSortFunction are called for initial sorting and when I click on grid headers to sort.

Example

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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new object[] { "test1", "test2", "test3" },
new object[] { "test4", "test5", "test6" },
new object[] { "test7", "test8", "test9" },
};
store.DataBind();
}
}
</script>

<!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 runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript">
Ext.util.Sorter.override({
constructor: function(config) {
alert("constructor");
var me = this;

Ext.apply(me, config);

//<debug>
if (me.property === undefined && me.sorterFn === undefined) {
Ext.Error.raise("A Sorter requires either a property or a sorter function");
}
//</debug>

me.updateSortFunction();
},

createSortFunction: function(sorterFn) {
alert("createSortFunction");
var me = this,
property = me.property,
direction = me.direction || "ASC",
modifier = direction.toUpperCase() == "DESC" ? -1 : 1;

//create a comparison function. Takes 2 objects, returns 1 if object 1 is greater,
//-1 if object 2 is greater or 0 if they are equal
return function(o1, o2) {
return modifier * sorterFn.call(me, o1, o2);
};
}
});
</script>
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test1" />
<ext:ModelField Name="test2" />
<ext:ModelField Name="test3" />
</Fields>
</ext:Model>
</Model>
<Sorters>
<ext:DataSorter Property="test" Direction="DESC" />
</Sorters>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test1" DataIndex="test1" />
<ext:Column runat="server" Text="Test2" DataIndex="test2" />
<ext:Column runat="server" Text="Test3" DataIndex="test3" />
</Columns>
</ColumnModel>
</ext:GridPanel>
</body>
</html>