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

Filter Template Javascript Code

3 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 20 May 2009, 01:02 AM
I have implemented a custom RadMenu that contains a RadCombobox to handle the
filtering for the column.  The RadComboBox is working perfectly, however, I am trying
to implement the javascript filter code used with the Filter Template and haven't had
any luck.  Below code gives me a "Cannot convert type 'System.Web.UI.Page' to
'Telerik.Web.UI.GridItem'" error on the var tableView.


Javascipt code located in <Body>

 

function test(sender, args) {

 

 

var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");

 

tableView.filter(columnname, args.get_item().get_value(),

"EqualTo");

 

}
ASPX CS Code to add RadComboBox

 

public

 

class MyTemplate : ITemplate

 

{

 

#region

 

ITemplate Members

 

 

public void InstantiateIn(Control container)

 

{

 

RadComboBox RCB = new RadComboBox();
RCB.ID="RCB_" + column1;

 

RCB.AutoPostBack =

true;

 

RCB.DataSourceID = RadGrid2.DataSourceID;

RCB.DataTextField = column1;

RCB.DataValueField = column1;

RCB.OnClientSelectedIndexChanged =

"test";

 

container.Controls.Add(RCB);

}

 

#endregion

 

 

}


I can't figure this one out.  Any ideas?

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 25 May 2009, 08:59 AM
Hello Josh,

To achieve your goal you need not to cast the container to GridItem when the Javascript method is placed in the body. You can use this code snippet to find the MasterTableView on the client:
var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();  

Best regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Josh
Top achievements
Rank 1
answered on 26 May 2009, 12:29 PM
I have modified my code to reflect what you suggested, however, the Grid does not filter.  The JS code
is contained within the body of the ASPX page and my grid is created dynamically.  It calls the function
just fine, but doesn't filter anything.  I have a seperate page that contains the same structure as the
Filter Template example and it still works fine after replacing the
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>"); 

 with

var tableView = $find("<%= RadGrid1.ClientID %>).get_masterTableView();. 

Could this be because my grid is created dynamically?  I have noticed that the Filter Template model will not
work correctly if the JS CodeBlocks are taken out of the <FilterTemplate> group.  Any ideas?

0
Georgi Krustev
Telerik team
answered on 28 May 2009, 01:31 PM
Hi Josh,

Based on this information, it is hard to determine what is causing this behavior. If the issue persists, you can open a formal support ticket, and send us the ASPX page and the code behind. We will review it locally, and advise you further.

Greetings,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Josh
Top achievements
Rank 1
Share this question
or