在 RadGrid FilterTemplate 中过滤加载数据
Filtering data on load in a RadGrid FilterTemplate
我有一个 RadGrid,它有一个使用 RadComboBox 的 FilterTemplate。当我在 RadGrid 中加载数据时,我想显示用户过滤的数据。这是我的专栏:
<telerik:GridTemplateColumn FilterControlAltText="Filter tclmArrangement column"
HeaderText="Arrangement" UniqueName="tclmArrangement" DefaultInsertValue="-"
DataField="IsDemoAssigned">
<HeaderStyle Width="2%" />
<ItemTemplate>
<asp:Repeater ID="rptchkarrangement" runat="server"
DataSource='<%# IIf(DataBinder.Eval(Container, "DataItem.IsDEmoAssigned") = 0,
DataBinder.Eval(Container, "DataItem.Employees"), Nothing)%> '>
<ItemTemplate>
<table>
<tr class="clsParent">
<input type="checkbox" class="clsEmployee" id="cbSelect"
checked='<%# DataBinder.Eval(Container, "DataItem.IsAssigned")%>'
runat="server" />
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FilterTemplate>
<telerik:RadComboBox ID="RadComboBoxAssignmentStatus" Height="80px" Width="80px"
AppendDataBoundItems="true" runat="server"
OnClientSelectedIndexChanged="AssignmentStatusIndexChanged">
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="rsbAssignmentStatus" runat="server">
<script type="text/javascript">
function AssignmentStatusIndexChanged(sender, args) {
var tableView = $find("<%# TryCast(Container,GridItem)
.OwnerTableView.ClientID %>");
var selectedValue = sender.get_value();
if (selectedValue) {
if (parseInt(selectedValue) < 0) {
tableView.filter("tclmArrangement", selectedValue, "NoFilter");
}
else {
tableView.filter("tclmArrangement", selectedValue, "EqualTo");
}
}
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
</telerik:GridTemplateColumn>
当最初使用“全部”选项显示完整数据时,过滤器工作正常。过滤器具有值(全部、已分配和未分配)。如何在 RadGrid 中显示属于未分配类别的数据?
不确定这是否是您想要的,但我通过 GridTemplateColumn DataFields 进行了过滤。我已经把中继器取下来了。
希望对你有所帮助
.aspx
<telerik:RadGrid ID="rg" runat="server" AutoGenerateColumns="false"
OnNeedDataSource="rg_NeedDataSource" AllowFilteringByColumn="true">
<MasterTableView>
<Columns>
<telerik:GridTemplateColumn DataField="IsAssigned" DefaultInsertValue="-"
UniqueName="tclmArrangement">
<HeaderStyle Width="2%" />
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server"
Checked='<%# Eval("IsAssigned") %>' />
<asp:Label ID="lbl" runat="server" Text='<%# Eval("EmployeeName") %>'>
</asp:Label>
</ItemTemplate>
<FilterTemplate>
<telerik:RadComboBox ID="rcbAssignmentStatus" Height="80px" Width="80px"
runat="server"
OnClientSelectedIndexChanged="AssignmentStatusIndexChanged"
SelectedValue='<%# ((GridItem)Container)
.OwnerTableView
.GetColumn("tclmArrangement").CurrentFilterValue %>'>
<Items>
<telerik:RadComboBoxItem Text="All" Value="" />
<telerik:RadComboBoxItem Text="All Assigned" Value="true" />
<telerik:RadComboBoxItem Text="Unassigned" Value="false" />
</Items>
</telerik:RadComboBox>
<telerik:RadCodeBlock ID="rcb" runat="server">
<script type="text/javascript">
function AssignmentStatusIndexChanged(sender, args) {
var tableView = $find('<%# ((GridItem)Container)
.OwnerTableView.ClientID %>');
var value = sender.get_selectedItem().get_value();
if (value != "")
tableView.filter('tclmArrangement', args.get_item()
.get_value(), 'EqualTo');
else
tableView.filter('tclmArrangement', args.get_item()
.get_value(), 'NoFilter')
}
</script>
</telerik:RadCodeBlock>
</FilterTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
.cs
protected void Page_Load(object sender, EventArgs e)
{
// Check
if (!IsPostBack)
{
// Variable
DataTable dt = new DataTable();
dt.Columns.Add("IsAssigned", typeof(bool));
dt.Columns.Add("EmployeeName", typeof(string));
string[] employeeName = { "Patrick", "Bucky", "Henry", "Jesus", "Linda" };
int[] isAssigned = { 1, 1, 0, 0, 0 };
// Loop
for (int i = 0; i < employeeName.Length; i++)
dt.Rows.Add(isAssigned[i], employeeName[i]);
ViewState["Data"] = dt;
rg.DataSource = dt;
rg.DataBind();
dt.Dispose();
}
}
protected void rg_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
rg.DataSource = ViewState["Data"] as DataTable;
}
这 link 帮助了我。
link 中未指定的一件事是设置 "EnableLinqExpression=false"
我选择了 "Setting the initial filter in the code-behind" 方法。过滤表达式可以组成如下
我有一个 RadGrid,它有一个使用 RadComboBox 的 FilterTemplate。当我在 RadGrid 中加载数据时,我想显示用户过滤的数据。这是我的专栏:
<telerik:GridTemplateColumn FilterControlAltText="Filter tclmArrangement column"
HeaderText="Arrangement" UniqueName="tclmArrangement" DefaultInsertValue="-"
DataField="IsDemoAssigned">
<HeaderStyle Width="2%" />
<ItemTemplate>
<asp:Repeater ID="rptchkarrangement" runat="server"
DataSource='<%# IIf(DataBinder.Eval(Container, "DataItem.IsDEmoAssigned") = 0,
DataBinder.Eval(Container, "DataItem.Employees"), Nothing)%> '>
<ItemTemplate>
<table>
<tr class="clsParent">
<input type="checkbox" class="clsEmployee" id="cbSelect"
checked='<%# DataBinder.Eval(Container, "DataItem.IsAssigned")%>'
runat="server" />
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FilterTemplate>
<telerik:RadComboBox ID="RadComboBoxAssignmentStatus" Height="80px" Width="80px"
AppendDataBoundItems="true" runat="server"
OnClientSelectedIndexChanged="AssignmentStatusIndexChanged">
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="rsbAssignmentStatus" runat="server">
<script type="text/javascript">
function AssignmentStatusIndexChanged(sender, args) {
var tableView = $find("<%# TryCast(Container,GridItem)
.OwnerTableView.ClientID %>");
var selectedValue = sender.get_value();
if (selectedValue) {
if (parseInt(selectedValue) < 0) {
tableView.filter("tclmArrangement", selectedValue, "NoFilter");
}
else {
tableView.filter("tclmArrangement", selectedValue, "EqualTo");
}
}
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
</telerik:GridTemplateColumn>
当最初使用“全部”选项显示完整数据时,过滤器工作正常。过滤器具有值(全部、已分配和未分配)。如何在 RadGrid 中显示属于未分配类别的数据?
不确定这是否是您想要的,但我通过 GridTemplateColumn DataFields 进行了过滤。我已经把中继器取下来了。
希望对你有所帮助
.aspx
<telerik:RadGrid ID="rg" runat="server" AutoGenerateColumns="false"
OnNeedDataSource="rg_NeedDataSource" AllowFilteringByColumn="true">
<MasterTableView>
<Columns>
<telerik:GridTemplateColumn DataField="IsAssigned" DefaultInsertValue="-"
UniqueName="tclmArrangement">
<HeaderStyle Width="2%" />
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server"
Checked='<%# Eval("IsAssigned") %>' />
<asp:Label ID="lbl" runat="server" Text='<%# Eval("EmployeeName") %>'>
</asp:Label>
</ItemTemplate>
<FilterTemplate>
<telerik:RadComboBox ID="rcbAssignmentStatus" Height="80px" Width="80px"
runat="server"
OnClientSelectedIndexChanged="AssignmentStatusIndexChanged"
SelectedValue='<%# ((GridItem)Container)
.OwnerTableView
.GetColumn("tclmArrangement").CurrentFilterValue %>'>
<Items>
<telerik:RadComboBoxItem Text="All" Value="" />
<telerik:RadComboBoxItem Text="All Assigned" Value="true" />
<telerik:RadComboBoxItem Text="Unassigned" Value="false" />
</Items>
</telerik:RadComboBox>
<telerik:RadCodeBlock ID="rcb" runat="server">
<script type="text/javascript">
function AssignmentStatusIndexChanged(sender, args) {
var tableView = $find('<%# ((GridItem)Container)
.OwnerTableView.ClientID %>');
var value = sender.get_selectedItem().get_value();
if (value != "")
tableView.filter('tclmArrangement', args.get_item()
.get_value(), 'EqualTo');
else
tableView.filter('tclmArrangement', args.get_item()
.get_value(), 'NoFilter')
}
</script>
</telerik:RadCodeBlock>
</FilterTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
.cs
protected void Page_Load(object sender, EventArgs e)
{
// Check
if (!IsPostBack)
{
// Variable
DataTable dt = new DataTable();
dt.Columns.Add("IsAssigned", typeof(bool));
dt.Columns.Add("EmployeeName", typeof(string));
string[] employeeName = { "Patrick", "Bucky", "Henry", "Jesus", "Linda" };
int[] isAssigned = { 1, 1, 0, 0, 0 };
// Loop
for (int i = 0; i < employeeName.Length; i++)
dt.Rows.Add(isAssigned[i], employeeName[i]);
ViewState["Data"] = dt;
rg.DataSource = dt;
rg.DataBind();
dt.Dispose();
}
}
protected void rg_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
rg.DataSource = ViewState["Data"] as DataTable;
}
这 link 帮助了我。
link 中未指定的一件事是设置 "EnableLinqExpression=false"
我选择了 "Setting the initial filter in the code-behind" 方法。过滤表达式可以组成如下