PDA

View Full Version : [CLOSED] GridPanel removeAll



softmachine2011
Sep 03, 2012, 11:43 AM
Hi,

When I try to remove all rows in a gridpanel from it store using grid.removeAll() it throws me an exception.

TEST CASE

<html>
<head runat="server">
<title>Ext.NET Example</title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
this.Store1.DataSource = this.Jobs;
this.Store1.DataBind();
}

private List<Job> Jobs
{
get
{
List<Job> jobs = new List<Job>();

for (int i = 1; i <= 50; i++)
{
jobs.Add(new Job(
i,
"Task" + i.ToString(),
DateTime.Today.AddDays(i),
DateTime.Today.AddDays(i + i),
(i % 3 == 0)));
}

return jobs;
}
}

public class Job
{
public Job(int id, string name, DateTime start, DateTime end, bool completed)
{
this.ID = id;
this.Name = name;
this.Start = start;
this.End = end;
this.Completed = completed;
}

public int ID { get; set; }
public string Name { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public bool Completed { get; set; }
}
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Button runat="server" Text="Test">
<Listeners>
<Click Handler="testGrid.removeAll();" />
</Listeners>
</ext:Button>
<ext:GridPanel ID="testGrid" runat="server" Header="false" Border="false" Height="300">
<Store>
<ext:Store ID="Store1" runat="server" PageSize="10">
<Model>
<ext:Model runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Start" Type="Date" />
<ext:ModelField Name="End" Type="Date" />
<ext:ModelField Name="Completed" Type="Boolean" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="ID" Width="40" Sortable="true" DataIndex="ID" />
<ext:Column runat="server" Text="Job Name" Sortable="true" DataIndex="Name" Flex="1" />
<ext:DateColumn runat="server" Text="Start" Width="120" Sortable="true" DataIndex="Start"
Format="yyyy-MM-dd" />
<ext:DateColumn runat="server" Text="End" Width="120" Sortable="true" DataIndex="End"
Format="yyyy-MM-dd" />
<ext:Column runat="server" Text="Completed" Width="80" Sortable="true" DataIndex="Completed">
<Renderer Handler="return (value) ? 'Yes':'No';" />
</ext:Column>
</Columns>
</ColumnModel>
<View>
<ext:GridView runat="server" LoadMask="false" />
</View>
<Features>
<ext:GridFilters runat="server" Local="true">
<Filters>
<ext:NumericFilter DataIndex="ID" />
<ext:StringFilter DataIndex="Name" />
<ext:DateFilter DataIndex="Start">
<DatePickerOptions runat="server" TodayText="Now" />
</ext:DateFilter>
<ext:DateFilter DataIndex="End">
<DatePickerOptions runat="server" TodayText="Now" />
</ext:DateFilter>
<ext:BooleanFilter DataIndex="Completed" />
</Filters>
</ext:GridFilters>
</Features>
<BottomBar>
<ext:PagingToolbar runat="server" DisplayInfo="true" DisplayMsg="Displaying Jobs {0} - {1} of {2}" />
</BottomBar>
</ext:GridPanel>
</form>
</body>
</html>

Is this the way or a way to remove elements from grid and store or there is a best way?

Daniil
Sep 03, 2012, 1:29 PM
Hi,

Now you are calling this method.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.container.AbstractContainer-method-removeAll (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.container.AbstractContainer-method-removeAll)


Please call the Store removeAll method.

testGrid.getStore().removeAll();
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-removeAll

softmachine2011
Sep 03, 2012, 2:53 PM
It works with your code.

Thanks