Hi,
I am trying to filter my gridview in onkeypress of the filter textbox.My mastertabelview dataitems returns zero and my sender.value is empty string.I got this code from a post here,but its not working.
Help me..
Thnx in advance
My code is:
I am trying to filter my gridview in onkeypress of the filter textbox.My mastertabelview dataitems returns zero and my sender.value is empty string.I got this code from a post here,but its not working.
Help me..
Thnx in advance
My code is:
Private Sub RadGridSpeciality_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridSpeciality.ItemCreated
If Not Page.IsPostBack Then
If TypeOf e.Item Is GridFilteringItem Then
Dim fltItem As GridFilteringItem = TryCast(e.Item, GridFilteringItem)
For Each column As GridColumn In RadGridSpeciality.Columns
Dim box As TextBox = TryCast(fltItem(column.UniqueName).Controls(0), TextBox)
box.Attributes.Add("onkeypress", "doFilter(this,event)")
Next
End If
End If
End Sub
function doFilter(sender, eventArgs) {
eventArgs.cancelBubble = true;
eventArgs.returnValue = false;
if (eventArgs.stopPropagation) {
eventArgs.stopPropagation();
eventArgs.preventDefault();
}
var masterTableView = $find("<%= RadGridSpeciality.ClientID %>").get_masterTableView();
var index = sender.parentNode.cellIndex; //index of the current column
var columns = masterTableView.get_columns();
uniqueName = columns[index].get_uniqueName();
masterTableView.filter(uniqueName, sender.value, Telerik.Web.UI.GridFilterFunction.Contains);
}
7 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 21 Mar 2012, 02:30 PM
Hi Remya,
Following is the code which I tried to perform search on key press. Please make sure that you have set AutoPostBackOnFilter property of a column to True. If you set so, the user does not need to press the filter button to initiate filtering. Instead, a postback filter operation occurs when the user types a filter in the filter box and presses [Enter] from the keyboard or if the filter textbox loses focus.
aspx:
C#:
Javascript:
Thanks,
-Shinu
Following is the code which I tried to perform search on key press. Please make sure that you have set AutoPostBackOnFilter property of a column to True. If you set so, the user does not need to press the filter button to initiate filtering. Instead, a postback filter operation occurs when the user types a filter in the filter box and presses [Enter] from the keyboard or if the filter textbox loses focus.
aspx:
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"EmployeeID"
UniqueName
=
"EmployeeID"
HeaderText
=
"EmployeeID"
AutoPostBackOnFilter
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
UniqueName
=
"FirstName"
HeaderText
=
"FirstName"
AutoPostBackOnFilter
=
"true"
>
</
telerik:GridBoundColumn
>
</
Columns
>
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(!Page.IsPostBack)
{
if
(e.Item
is
GridFilteringItem)
{
GridFilteringItem fltItem = e.Item
as
GridFilteringItem;
foreach
(GridColumn column
in
RadGrid1.Columns)
{
TextBox box = fltItem[column.UniqueName].Controls[0]
as
TextBox;
box.Attributes.Add(
"onkeypress"
,
"doFilter(this,event)"
);
}
}
}
}
Javascript:
function
doFilter(sender, eventArgs)
{
if
((eventArgs.keyCode == 13 || eventArgs.keyCode == 9) && (sender.value !=
""
))
{
eventArgs.cancelBubble =
true
;
eventArgs.returnValue =
false
;
if
(eventArgs.stopPropagation)
{
eventArgs.stopPropagation();
eventArgs.preventDefault();
}
var
masterTableView = $find(
"<%= RadGrid1.ClientID %>"
).get_masterTableView();
var
index = sender.parentNode.cellIndex;
//index of the current column
var
columns = masterTableView.get_columns();
uniqueName = columns[index].get_uniqueName();
masterTableView.filter(uniqueName, sender.value, Telerik.Web.UI.GridFilterFunction.Contains);
}
}
Thanks,
-Shinu
0

Remya
Top achievements
Rank 1
answered on 22 Mar 2012, 06:46 AM
Hi,
Thanks for the reply.But my issue is that am not getting the text inside filter textbox ie; sender.value.
plz help
Thanks for the reply.But my issue is that am not getting the text inside filter textbox ie; sender.value.
plz help
0

Shinu
Top achievements
Rank 2
answered on 22 Mar 2012, 07:26 AM
Hi Remya,
You can
perform filtering on Radgrid with Enter key either by setting AutoPostBackOnFilter
property of a column to True. Or you can try it from the client side code
which I have given in the previous post. I am sorry that I confused you by
giving both the methods.
0

Remya
Top achievements
Rank 1
answered on 22 Mar 2012, 08:13 AM
Hi,
Can you please tell me how to find the gridfilteringitem or the corresponding filter textbox in the keypress of grid.
Thnx in advance
Can you please tell me how to find the gridfilteringitem or the corresponding filter textbox in the keypress of grid.
Thnx in advance
0

Shinu
Top achievements
Rank 2
answered on 22 Mar 2012, 08:38 AM
Hi Remya,
You can access the filter TextBox directly from the sender argument. Please take a look into the code.
Javascript:
Thanks,
-Shinu.
You can access the filter TextBox directly from the sender argument. Please take a look into the code.
Javascript:
<script type=
"text/javascript"
>
function
doFilter(sender, eventArgs)
{
var
textbox = sender;
//accessing the filter Textbox
//. . .
}
</script>
Thanks,
-Shinu.
0

Remya
Top achievements
Rank 1
answered on 22 Mar 2012, 01:25 PM
Hi,
Thanks Shinu for the reply.
I have set the AutoPostBackOnFilter="true" and I am calling a keypress event for grid for my own purpose.I had implemented a keypress event for the filter textbox in ItemCreated event.But still i am unable to enter any values in the filter textbox, i don't know whether it is getting cleared or it became read only.
Thanks Shinu for the reply.
I have set the AutoPostBackOnFilter="true" and I am calling a keypress event for grid for my own purpose.I had implemented a keypress event for the filter textbox in ItemCreated event.But still i am unable to enter any values in the filter textbox, i don't know whether it is getting cleared or it became read only.
0
Hello,
Could you post your RadGrid declaration along with the respective event handlers? Thus all the people who want to help you will have better understanding of your code.
Kind regards,
Andrey
the Telerik team
Could you post your RadGrid declaration along with the respective event handlers? Thus all the people who want to help you will have better understanding of your code.
Kind regards,
Andrey
the Telerik team
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.