PDA

View Full Version : [CLOSED] Reset Grid



CanopiusApplications
Jan 16, 2014, 9:41 AM
Guys

I am looking for a way to reset a grid sort state (probably simple but I can't seem to find it).
I have tried all sorts with no luck.

1.
X.AddScript("delete Store1.sortInfo;");
2.
Store1.Set("sortInfo", null);

I can however do this from code behind

1.
GenericStore.Sort("Code", SortDirection.ASC);

But what I am looking for is a way to clear the sort as when the form is opened the database will have handled the default sort.

Thanks in advance,
D

CanopiusApplications
Jan 16, 2014, 9:52 AM
Just to follow on.

In fact it would be ideal if there was a way to reset the grid to it's default state (Col width, Sort, Paging, Filters) all in a single call much like what happens here -- http://examples2.ext.net/#/GridPanel/Data_Presentation/Grid_and_Store_Reconfigure/

Ideally though I do not want to have to rebuild everything on page load as the columns never change.

The reason for this is the grid is displaying different data sources all with the same structure -- I am using a generic user control to maintain data from different tables that have the same structure.

ta,
D

Daniil
Jan 16, 2014, 2:10 PM
Hi @CanopiusApplications,

As for resetting sort state.

I think you should clear a Store's sorters and re-bind the data.

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)
{
this.DataBind(false);
}
}

protected void Rebind(object sender, DirectEventArgs e)
{
this.DataBind(true);
}

private void DataBind(bool resetSort = false)
{
Store store = this.GridPanel1.GetStore();

if (resetSort)
{
store.Call("sorters.clear");
}

store.DataSource = new object[]
{
new object[] { "c", "test" },
new object[] { "a", "test" },
new object[] { "b", "test" }
};
store.DataBind();
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test1" />
<ext:ModelField Name="test2" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test 1" DataIndex="test1" />
<ext:Column runat="server" Text="Test 2" DataIndex="test2" />
</Columns>
</ColumnModel>
</ext:GridPanel>

<ext:Button runat="server" Text="Rebind" OnDirectClick="Rebind" />
</form>
</body>
</html>

As for resetting a GridPanel at all, here is a related discussion.
http://forums.ext.net/showthread.php?14637

CanopiusApplications
Jan 16, 2014, 3:41 PM
thanks D that is what I was after.

CanopiusApplications
Jan 17, 2014, 11:45 AM
Hi D

I have found that doing the following reset my grid to it's initial state.




gpAllFilters.ClearFilters();
gpAllPaging.MoveFirst();
GenericStore.Call("sorters.clear");
gpAll.Reconfigure();
gpAll.Refresh();



D

Daniil
Jan 17, 2014, 11:54 AM
Ok, if it is enough for your case, it is good.