Hi,
I have a radGrid on my aspx page, where filters on columns should have default function as "Contains". I am able to do this in grid's itemdatabound event. when the user searches from filter box it should check for "Contains", but he can use other filter functions like "starts with" and "ends with' by clicking on filter icon. But after typing search value, he chooses say for ex. "Ends with" from filter menu, the results should be bound with items matching "ends with" search text. Soon after the results are bound, filter function should change to "Contains". Help me with this
Thanks,
Farjana
I have a radGrid on my aspx page, where filters on columns should have default function as "Contains". I am able to do this in grid's itemdatabound event. when the user searches from filter box it should check for "Contains", but he can use other filter functions like "starts with" and "ends with' by clicking on filter icon. But after typing search value, he chooses say for ex. "Ends with" from filter menu, the results should be bound with items matching "ends with" search text. Soon after the results are bound, filter function should change to "Contains". Help me with this
Thanks,
Farjana
15 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Dec 2013, 10:54 AM
Hi Farjana,
I guess after any filter you want "Contains" filter-function to be selected in the options, for that set the CurrentFilterFunction property in the Page_PreRender event for the page as follows:
C#:
Thanks,
Princy
I guess after any filter you want "Contains" filter-function to be selected in the options, for that set the CurrentFilterFunction property in the Page_PreRender event for the page as follows:
C#:
protected
override
void
OnPreRender(EventArgs e)
{
base
.OnPreRender(e);
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe(
"ColumnUniqueName"
);
column.CurrentFilterFunction = GridKnownFunction.Contains;
RadGrid1.Rebind();
}
Thanks,
Princy
0
Farjana
Top achievements
Rank 1
answered on 07 Jan 2014, 06:48 AM
Hi Princy,
Thanks for the previous solution. It worked.
Another Clarification: I have a radgrid. In the itemDatabound event of the radgrid, I want to find the column name to which the GridDataItem belongs to.
Can you please tell me how to do?
Thanks,
Farjana
Thanks for the previous solution. It worked.
Another Clarification: I have a radgrid. In the itemDatabound event of the radgrid, I want to find the column name to which the GridDataItem belongs to.
Can you please tell me how to do?
Thanks,
Farjana
0
Princy
Top achievements
Rank 2
answered on 07 Jan 2014, 08:01 AM
Hi Farjana,
I guess you want to access the columns of RadGrid in the ItemDataBound event. You can access them using its HeaderText or UniqueName property as shown below:
C#:
Thanks,
Princy
I guess you want to access the columns of RadGrid in the ItemDataBound event. You can access them using its HeaderText or UniqueName property as shown below:
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
foreach
(GridColumn col
in
RadGrid1.MasterTableView.Columns)
{
string
columnuniquename = col.UniqueName;
// Get Column Name using UniqueName
string
columnheadertext = col.HeaderText;
// Get Column Name using HeaderText
}
}
}
Thanks,
Princy
0
Farjana
Top achievements
Rank 1
answered on 07 Jan 2014, 08:09 AM
Hi Princy,
Thanks for the suggestion. I have tried out that way already.
Actually, I am accessing the table cells in databound event like this:
Thanks for the suggestion. I have tried out that way already.
Actually, I am accessing the table cells in databound event like this:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{ GridDataItem item = (GridDataItem)e.Item;
foreach (TableCell cell in item.Cells)
{
// I need to identify the unique column name with either the cell or dataitem
}
}
}
0
Princy
Top achievements
Rank 2
answered on 08 Jan 2014, 03:29 AM
Hi Farjana,
Please try the following code snippet if you want to access using TableCell:
C#:
Thanks,
Princy
Please try the following code snippet if you want to access using TableCell:
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
foreach
(GridColumn col
in
RadGrid1.MasterTableView.Columns)
{
TableCell cell = item[col.UniqueName];
string
value = cell.Text;
// get the values of the columns
}
}
}
Thanks,
Princy
0
Farjana
Top achievements
Rank 1
answered on 08 Jan 2014, 06:41 AM
Hi Princy,
Thanks for the previous soln.
A clarification regarding previous port Radgrid filters:
I have 10 columns in a grid. I would like to give different filter menu options for the columns.
I have tried the following code:
function filterMenushowing(sender, eventArgs) {
if (eventArgs.get_column().get_uniqueName() == "Exp_DlvryDate") {
var menu = eventArgs.get_menu();
var items = menu._itemData;
var i = 0;
while (i < items.length) {
if (items[i].value != "Contains" && items[i].value != "EqualTo" && items[i].value != "GreaterThan") {
var item = menu._findItemByValue(items[i].value);
if (item != null)
item._element.style.display = "none";
}
i++;
}
}
else {
var menu1 = eventArgs.get_menu();
var items1 = menu1._itemData;
var j = 0;
while (j < items1.length) {
if (items1[j].value != "Contains" && items1[j].value != "EqualTo") {
var item1 = menu1._findItemByValue(items1[j].value);
if (item1 != null)
item1._element.style.display = "none";
}
j++;
}
}
}
If i click the column with unique name "Exp_DlvryDate", I am able to see three options, "Contains,EqualTo,GreaterThan".
when i click some other column filter, I am able to see three options, "Contains,EqualTo".
But when i come back to "Exp_DlvryDate" column and clicks on filter only two options are displayed (Contains,EqualTo)
I guess the filter menu is commonly getting modified. Can you pls tell me where exactly it is going wrong.
Thanks,
Farjana
Thanks for the previous soln.
A clarification regarding previous port Radgrid filters:
I have 10 columns in a grid. I would like to give different filter menu options for the columns.
I have tried the following code:
function filterMenushowing(sender, eventArgs) {
if (eventArgs.get_column().get_uniqueName() == "Exp_DlvryDate") {
var menu = eventArgs.get_menu();
var items = menu._itemData;
var i = 0;
while (i < items.length) {
if (items[i].value != "Contains" && items[i].value != "EqualTo" && items[i].value != "GreaterThan") {
var item = menu._findItemByValue(items[i].value);
if (item != null)
item._element.style.display = "none";
}
i++;
}
}
else {
var menu1 = eventArgs.get_menu();
var items1 = menu1._itemData;
var j = 0;
while (j < items1.length) {
if (items1[j].value != "Contains" && items1[j].value != "EqualTo") {
var item1 = menu1._findItemByValue(items1[j].value);
if (item1 != null)
item1._element.style.display = "none";
}
j++;
}
}
}
If i click the column with unique name "Exp_DlvryDate", I am able to see three options, "Contains,EqualTo,GreaterThan".
when i click some other column filter, I am able to see three options, "Contains,EqualTo".
But when i come back to "Exp_DlvryDate" column and clicks on filter only two options are displayed (Contains,EqualTo)
I guess the filter menu is commonly getting modified. Can you pls tell me where exactly it is going wrong.
Thanks,
Farjana
0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Jan 2014, 05:44 AM
Hi Farjana,
Please try the sample code snippet that i tried which works fine at my end:
ASPX:
C#:
JS:
Thanks,
Princy
Please try the sample code snippet that i tried which works fine at my end:
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowFilteringByColumn
=
"true"
EnableLinqExpressions
=
"false"
>
<
MasterTableView
DataKeyNames
=
"ID"
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"ID"
DataField
=
"ID"
HeaderText
=
"ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Name"
HeaderText
=
"Name"
UniqueName
=
"Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Number"
HeaderText
=
"Number"
UniqueName
=
"Number"
DataType
=
"System.Int16"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"false"
/>
<
ClientEvents
OnFilterMenuShowing
=
"filterMenuShowing"
/>
</
ClientSettings
>
<
FilterMenu
OnClientShown
=
"MenuShowing"
/>
</
telerik:RadGrid
>
C#:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
dynamic data =
new
[] {
new
{ ID = 1, Name =
"Name1"
, Number=123},
new
{ ID = 2, Name =
"Name2"
, Number=456},
new
{ ID = 3, Name =
"Name3"
, Number=789},
new
{ ID = 4, Name =
"Name4"
, Number=123},
new
{ ID = 5, Name =
"Name5"
, Number=258}
};
RadGrid1.DataSource = data;
}
JS:
<script type=
"text/javascript"
>
var
column =
null
;
var
columnName =
null
;
function
MenuShowing(sender, args) {
if
(column ==
null
)
return
;
if
(columnName ==
null
)
return
;
var
menu = sender;
var
items = menu.get_items();
if
(columnName ==
"Name"
) {
var
i = 0;
while
(i < items.get_count()) {
if
(!(items.getItem(i).get_value()
in
{
'StartsWith'
:
''
,
'Contains'
:
''
})) {
var
item = items.getItem(i);
if
(item !=
null
)
item.set_visible(
false
);
}
else
{
var
item = items.getItem(i);
if
(item !=
null
)
item.set_visible(
true
);
} i++;
}
}
else
{
if
(columnName ==
"Number"
) {
var
j = 0;
while
(j < items.get_count()) {
if
(!(items.getItem(j).get_value()
in
{
'EqualTo'
:
''
,
'NotEqualTo'
:
''
})) {
var
item = items.getItem(j);
if
(item !=
null
)
item.set_visible(
false
);
}
else
{
var
item = items.getItem(j);
if
(item !=
null
)
item.set_visible(
true
);
} j++;
}
}
}
column =
null
;
columnName =
null
;
}
function
filterMenuShowing(sender, eventArgs) {
column = eventArgs.get_column();
columnName = eventArgs.get_column().get_uniqueName();
}
</script>
Thanks,
Princy
0
Farjana
Top achievements
Rank 1
answered on 16 Jan 2014, 07:13 AM
Hi Princy,
When i introduce filters in the radgrid, the width of the column is inconsistent. See the attached screenshot. the filter menu icons are hidden and every time i need to adjust width manually. Can you pls tell me how to handle it.
When i introduce filters in the radgrid, the width of the column is inconsistent. See the attached screenshot. the filter menu icons are hidden and every time i need to adjust width manually. Can you pls tell me how to handle it.
0
Princy
Top achievements
Rank 2
answered on 17 Jan 2014, 09:19 AM
Hi Farjana,
Can you try setting the following CSS to your RadGrid.
CSS:
Thanks,
Princy
Can you try setting the following CSS to your RadGrid.
CSS:
<style type=
"text/css"
>
div.RadGrid .rgFilterRow td
{
padding-right
:
30px
;
}
</style>
Thanks,
Princy
0
Farjana
Top achievements
Rank 1
answered on 29 Jan 2014, 06:30 AM
Hi Princy,
For the radgrid in my page, i have an option to save the column preferences(using GridSettingsPersister class). So, I am not able to set static width for the filter icon, since the settings saved by user(using GridSettingsPersister class) is overwritten when i assign a static width.
Please suggest a solution.
For the radgrid in my page, i have an option to save the column preferences(using GridSettingsPersister class). So, I am not able to set static width for the filter icon, since the settings saved by user(using GridSettingsPersister class) is overwritten when i assign a static width.
Please suggest a solution.
0
Hello Farjana,
I am not sure what exactly you issue is. Could you please try to set the FilterStyle.Width property for the corresponding columns instead of the provided CSS. Take this demo for instance, what should be changed in order to replicate the problem in it?
Regards,
Venelin
Telerik
I am not sure what exactly you issue is. Could you please try to set the FilterStyle.Width property for the corresponding columns instead of the provided CSS. Take this demo for instance, what should be changed in order to replicate the problem in it?
Regards,
Venelin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Mayur
Top achievements
Rank 1
answered on 11 Apr 2014, 05:24 AM
Dear Princy,
I am working on RadGrid with Filter options. I am stucked in filtering provision in which I need your help. This is my scenario.
As you can see in the attached code file, I am using Templated grid with ShowFilterIcon = "True" AutoPostBackOnFilter="true"
AllowFiltering="true" attributes.
But Still filtering is not working. Here grid is rebinding but displaying the same result.
So do i have to write any additional code over there or do you have some other trick to apply. Please send me sample code
I am working on RadGrid with Filter options. I am stucked in filtering provision in which I need your help. This is my scenario.
As you can see in the attached code file, I am using Templated grid with ShowFilterIcon = "True" AutoPostBackOnFilter="true"
AllowFiltering="true" attributes.
But Still filtering is not working. Here grid is rebinding but displaying the same result.
So do i have to write any additional code over there or do you have some other trick to apply. Please send me sample code
0
Princy
Top achievements
Rank 2
answered on 11 Apr 2014, 06:27 AM
Hi Mayur,
Please set the DataField property of the GridTemplateColumn for filtering the column.
ASPX:
Thanks,
Princy
Please set the DataField property of the GridTemplateColumn for filtering the column.
ASPX:
<
telerik:GridTemplateColumn
DataField
=
"CA_MEMBER_ID"
AllowFiltering
=
"true"
. . >
Thanks,
Princy
0
Asutosh
Top achievements
Rank 1
answered on 25 Jul 2014, 11:37 AM
hi princy
i am using radgrid in my page and i used onneeddatasource to bind it
i have open filter functionality for that
but it take too much time for filtering and also in pagging change it take too much time
i am using radgrid in my page and i used onneeddatasource to bind it
i have open filter functionality for that
but it take too much time for filtering and also in pagging change it take too much time
0
Princy
Top achievements
Rank 2
answered on 29 Jul 2014, 03:53 AM
Hi Asutosh,
You can take a look at the following article and the documentations coming under the Performance session to know how to increase the performance of your Grid.
Client/server grid performance optimizations
Thanks,
Princy
You can take a look at the following article and the documentations coming under the Performance session to know how to increase the performance of your Grid.
Client/server grid performance optimizations
Thanks,
Princy