PDA

View Full Version : [CLOSED] How To Adding Filter, Grouping, Refresh Feature by Code (Server side)



yuda236
Jul 23, 2014, 5:34 AM
Hi,

I developed Grid By Code this My Code

Aspx.



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Transform2GridExample.aspx.cs" Inherits="WEB.Transform2GridExample" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Import Namespace="Ext.Net.Utilities" %>
<%@ Import Namespace="System.Collections.Generic" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Viewport runat="server" ID="ViewPort">
<Items>
<ext:Button runat="server" Text="LoadData1" Icon="Add" Width="200" ID="LoadData">
<DirectEvents>
<Click OnEvent = "LoadData1" />
</DirectEvents>
</ext:Button>

<ext:GridPanel
ID="GPMAIN"
runat="server"
Title="Grid"
Width="600"
Height="350">
<Store>
<ext:Store
ID="Store1"
runat="server"
IgnoreExtraFields="false">
<Model>
<ext:Model ID="Model1" runat="server" />
</Model>
</ext:Store>
</Store>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single" />
</SelectionModel>
</ext:GridPanel>

</Items>
</ext:Viewport>


</form>
</body>
</html>



c#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;
using System.Xml;
using System.Configuration;
using System.Xml.Xsl;

namespace WEB
{
public partial class Transform2GridExample : System.Web.UI.Page
{
LocalClass LC = new LocalClass();
localhost.WebService1 WS = new localhost.WebService1();
protected void Page_Load(object sender, EventArgs e)
{

}

protected void LoadData1(object sender, DirectEventArgs e)
{
BuildSet1();

}


private void BuildSet1()
{
DataTable DT = WS.DashboardPembelianALLCity();
if (X.IsAjaxRequest)
{
this.Store1.RemoveFields();
}

for (int i = 0; i < DT.Columns.Count; i++)
{
string NameHeader = DT.Columns[i].ColumnName.ToString();
this.Store1.AddField(new ModelField(NameHeader, SetTypeFromColumn(DT.Columns[i])));
}

this.Store1.RebuildMeta();

for (int i = 0; i < DT.Columns.Count; i++)
{
string NameHeader = DT.Columns[i].ColumnName.ToString();
this.GPMAIN.ColumnModel.Columns.Add(new Column { DataIndex = NameHeader, Text = NameHeader });
}

Store1.DataSource = DT;
Store1.DataBind();

if (X.IsAjaxRequest)
{
this.GPMAIN.Reconfigure();
}
}


public Ext.Net.ModelFieldType SetTypeFromColumn(DataColumn DC)
{

if (DC.DataType == typeof(bool))
{
return Ext.Net.ModelFieldType.Boolean;
}
if (DC.DataType == typeof(Int32))
{
return Ext.Net.ModelFieldType.Int;
}
if (DC.DataType == typeof(float))
{
return Ext.Net.ModelFieldType.Float;
}
if (DC.DataType == typeof(Double))
{
return Ext.Net.ModelFieldType.Int;
}

return Ext.Net.ModelFieldType.String;
}

}
}



How can I add a filter ,Grouping and Refresh Feature in Code ? ( Im Build Grid In BuildSet1())

Thx

Yuda

Daniil
Jul 23, 2014, 12:49 PM
Hi @yuda236,

A GridPanel's Reconfigure method is to reconfigure its ColumnModel and Store. If you need to add features or plugins or something else, you have to re-render a GridPanel after configuring everything.

grid.ReRender();

yuda236
Jul 24, 2014, 1:17 AM
Hi Daniil,

How Method for add filter ,Grouping and Refresh feature in code ?

can you give me example or other thread with relation with this problem ?

Thanks

Yuda

Daniil
Jul 24, 2014, 8:46 AM
Those markup and code produce the same result.

<ext:GridPanel ID="GridPanel1" runat="server">
<Features>
<ext:GridFilters runat="server">
<Filters>
<ext:StringFilter DataIndex="someField" />
</Filters>
</ext:GridFilters>
<ext:Grouping runat="server" />
</Features>
</ext:GridPanel>


GridPanel grid = new GridPanel
{
Features =
{
new GridFilters
{
Filters =
{
new StringFilter { DataIndex = "some field" }
}
},

new Grouping()
}
};

Hope this helps.