This is a migrated thread and some comments may be shown as answers.

Filter Grid with Single Click

2 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henry Derstine
Top achievements
Rank 1
Henry Derstine asked on 16 Oct 2008, 12:56 PM
I may be missing this because it seems simple. Is there a way to filter immediatey when the filter image is clicked. I will always use only the contains filter and do not need the extra step of the menu from opening. I tried to add a "search" link button in the filter row but I can not get the correct arguments to be passed to the commanditem event. I was thinking I was making it more complicated then i needed to. Thanks for any help

2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 16 Oct 2008, 01:33 PM
Hello Henry,

I've made small example to illustrate you how to hide the filter image and how to use CurrentFilterFunction and AutoPostBackOnFilter column properties. You can find the example attached.

Regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Henry Derstine
Top achievements
Rank 1
answered on 16 Oct 2008, 01:51 PM
Thanks, that worked but I figured a different way to do it with the linkbtn.

FYI (In this scenario I am only filtering on one col)-

Protected

Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated

 

 

If TypeOf e.Item Is GridFilteringItem Then

 

 

Dim filteringItem As GridFilteringItem = CType(e.Item, GridFilteringItem)

 

 

'set dimensions for the filter textbox

 

 

Dim box As TextBox = CType(filteringItem("Name").Controls(0), TextBox)

 

box.Width = Unit.Pixel(150)

filteringItem(

"Name").Controls(1).Visible = False

 

 

Dim aSpacer As New Literal

 

aSpacer.Text =

" "

 

filteringItem(

"Name").Controls.Add(aSpacer)

 

 

Dim alnkBtn1 As New LinkButton

 

alnkBtn1.Text =

"Filter Results"

 

alnkBtn1.CommandName =

"FilterMe"

 

alnkBtn1.CommandArgument = box.Text

filteringItem(

"Name").Controls.Add(alnkBtn1)

 

 

Dim aSpacer2 As New Literal

 

aSpacer2.Text =

"       "

 

filteringItem(

"Name").Controls.Add(aSpacer2)

 

 

Dim alnkBtn As New LinkButton

 

alnkBtn.Text =

"Clear Filter"

 

alnkBtn.CommandName =

"ClearFilter"

 

filteringItem(

"Name").Controls.Add(alnkBtn)

 

 

End If

 

 

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand

 

 

If (e.CommandName = "ClearFilter") Then

 

 

 

 

For Each column As GridColumn In RadGrid1.MasterTableView.Columns

 

column.CurrentFilterFunction = GridKnownFunction.NoFilter

column.CurrentFilterValue =

String.Empty

 

 

Next

 

 

 

RadGrid1.MasterTableView.FilterExpression =

String.Empty

 

RadGrid1.MasterTableView.Rebind()

 

End If

 

 

 

 

If e.CommandName = "FilterMe" Then

 

 

 

 

If CType(CType(e.Item, GridFilteringItem)("Name").Controls(0), TextBox).Text.Trim.Length > 0 Then

 

 

 

RadGrid1.MasterTableView.FilterExpression =

"([Name] LIKE '%" & CType(CType(e.Item, GridFilteringItem)("Name").Controls(0), TextBox).Text & "%')"

 

 

 

RadGrid1.MasterTableView.Rebind()

 

Else

 

 

 

 

End If

 

 

 

 

 

End If

 

 

 

 

End Sub

 

Tags
Grid
Asked by
Henry Derstine
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Henry Derstine
Top achievements
Rank 1
Share this question
or