PDA

View Full Version : [CLOSED] Retaining grid filter on cell editing



vmehta
Oct 07, 2014, 2:31 PM
Hello,

I am loading a grid and saving the data on cell edit. I have been doing this with the help of this example "Editable GridPanel With Save To [DirectMethod]". I also have filter headers tof ilter data. When I filter the data and then change a column value, the grid saves the cell changes and loads removing the filter conditions. Is there a way to retain the filters/sorting even after the grid is loaded after save.

Daniil
Oct 08, 2014, 2:36 PM
Hi @vmehta,

Do you use local sorting and filtering? If so, you should save the sort and filtering state before saving and restore it after.

For example, you can retrieve currently applied sorters:

store.getSorters()

Then I would try to re-apply it using a Store's sort method.

vmehta
Oct 09, 2014, 10:44 AM
Yes, I am using local filters and sorters. There is no issue with the sorters. Even without saving sorters, it gets sorted after editing.
Is there a way to get the filters before editing and then apply them?

vmehta
Oct 09, 2014, 2:18 PM
Here is the sample of how I do filtering. When data is filtered and then a cell is edited, the grid is refreshed and filter is removed.
All the records without filter is loaded.


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

<%@ Import Namespace="System.Collections.Generic" %>

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

<script runat="server">
public class Company
{
public int ID { get; set; }
public string Name { get; set; }
public double Price { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.BindData();
}
}

private void BindData()
{
Store store = this.GridPanel1.GetStore();
store.DataSource = this.GetData();
store.DataBind();
}

private List<Company> GetData()
{
DateTime today = DateTime.Today;

return new List<Company>
{
new Company { ID = 1, Name = "3m Co", Price = 71.72 },
new Company { ID = 2, Name = "Alcoa Inc", Price = 29.01},
new Company { ID = 3, Name = "Altria Group Inc", Price = 83.81},
new Company { ID = 4, Name = "American Express Company", Price = 52.55},
new Company { ID = 5, Name = "American International Group, Inc.", Price = 64.13},
new Company { ID = 6, Name = "AT&T Inc.", Price = 31.61},
new Company { ID = 7, Name = "Boeing Co.", Price = 75.43},

};
}

[DirectMethod(Namespace = "CompanyX")]
public void Edit(int id, string field, string oldValue, string newValue, object customer)
{
this.BindData();
}
</script>

<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Editor with DirectMethod - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />

<script>
var edit = function (editor, e) {

if (!(e.value === e.originalValue || (Ext.isDate(e.value) && Ext.Date.isEqual(e.value, e.originalValue)))) {
CompanyX.Edit(e.record.data.ID, e.field, e.originalValue, e.value, e.record.data);
}
};
</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:GridPanel
ID="GridPanel1"
runat="server"
Width="600"
Height="350">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Price" Type="Float" />

</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" Width="35" />
<ext:Column ID="Column2" runat="server" Text="Name" DataIndex="Name" Flex="1">
<Editor>
<ext:TextField ID="TextField1" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column3" runat="server" Text="Price" DataIndex="Price">
<Renderer Format="UsMoney" />
<Editor>
<ext:NumberField ID="NumberField1" runat="server" />
</Editor>
</ext:Column>


</Columns>
</ColumnModel>
<SelectionModel>
<ext:CellSelectionModel ID="CellSelectionModel1" runat="server" />
</SelectionModel>
<Plugins>
<ext:CellEditing ID="CellEditing1" runat="server" ClicksToEdit="1">
<Listeners>
<Edit Fn="edit" />
</Listeners>
</ext:CellEditing>
<ext:FilterHeader ID="FilterHeader1" runat="server" />
</Plugins>

</ext:GridPanel>
</form>
</body>
</html>

Daniil
Oct 09, 2014, 7:40 PM
Thank you for the test case.

Please try this.

[DirectMethod(Namespace = "CompanyX")]
public void Edit(int id, string field, string oldValue, string newValue, object customer)
{
this.BindData();
this.FilterHeader1.ApplyFilter();
}