I'm having a problem passing multiple paramters to the my controller using the rebind method.
Here is some sample javacript that works ok (1 rebind parameter)
| function BindGrid() { |
| var firstNameSearchTerm = $('#FirstNameSearch').val(); |
| var lastNameSearchTerm = $('#LastNameSearch').val(); |
| var grid = $("#MyGrid").data("tGrid"); |
| grid.rebind({ firstNameSearchTerm: firstNameSearchTerm}); |
| } |
When I try to pass in a second param things start to go wrong
| function BindGrid() { |
| var firstNameSearchTerm = $('#FirstNameSearch').val(); |
| var lastNameSearchTerm = $('#LastNameSearch').val(); |
| var grid = $("#MyGrid").data("tGrid"); |
| grid.rebind({ firstNameSearchTerm: firstNameSearchTerm, lastNameSearchTerm: lastNameSearchTerm}); |
| } |
When I use Firebug to look at the params being posted I get: firstNameSearchTerm
BilllastNameSearchTerm=GatesCan I use a comma to separate my parameters?
Can the rebind method take more than one parameter? If not should I be putting all my search strings into a collection and pass that to the rebind method?
18 Answers, 1 is accepted
This is a known issue with the rebind method. Please check this forum thread for a resolution.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Which version are you using? The forum thread mentioned earlier contains the fix for any version older than 2009.3.1320.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
| rebind: function(args) { |
| this.sorted = []; |
| this.filterBy = ''; |
| this.currentPage = 1; |
| $.each(this.columns, function() { |
| this.order = null; |
| this.filters = []; |
| }); |
| $('.t-filter-options', this.element) |
| .find('input[type="text"], select') |
| .val('') |
| .removeClass('t-state-error'); |
| for (var key in args) { |
| var regExp = new RegExp($t.formatString('({0})=([^&]*)', key), 'g'); |
| if (regExp.test(this.ajax.selectUrl)) |
| this.ajax.selectUrl = this.ajax.selectUrl.replace(regExp, '$1=' + args[key]); |
| else { |
| var url = new $t.stringBuilder(); |
| url.cat(this.ajax.selectUrl); |
| if (this.ajax.selectUrl.indexOf('?') < 0) |
| url.cat('?'); |
| else |
| url.cat('&'); |
| this.ajax.selectUrl = url.cat(key).cat('=').cat(args[key]).string(); |
| } |
| } |
| this.ajaxRequest(); |
| } |
No, this fix won't ship with Q1 2010 since the problem was discovered after we shipped.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
This is a rather old thread (more than year old). Are you using the same version which is discussed here? Or you have probably hit the change in behavior of the rebind method. The latter is described here.
Best wishes,Atanas Korchev
the Telerik team
Can you paste the code which you are using? It is not clear now what has gone wrong.
Greetings,Atanas Korchev
the Telerik team
function initGridEvents(){
$('a.t-refresh').click(
function(event){
//event.preventDefault();
//Rebind the grid
var grid = $("#PCPGrid").data("tGrid");
grid.rebind({practitionerSpecialty : ''});
}
);
}
In the code above, '$('a.t-refresh')' is a jquery selector to retrieve the refresh link in the lower left corner of the grid. The function is called after the grid has been already been bound with a value for practitionerSpecialty during the page load, and I am attempting to rebind the grid with the value for practitionerSpecialty cleared, so that the grid is no longer filtered by practitionerSpecialty. I am attempting to capture the click event on the grid's refresh button and rebind manually. Perhaps there is a different approach?
After debugging in Firefox, I've noticed that rebind fails on line 721, which reads as:
if (regExp.test(this.ajax.selectUrl))
The failure ocurs because 'ajax' is undefined. 'this' refers to the grid.
Could it be that your grid is not ajax bound? The rebind method works for ajax bound grids only.
Regards,Atanas Korchev
the Telerik team
@(
Html.Telerik().Grid(Model.PractitionerDisplayItems).Name("PractitionersGrid").Pageable(pager => pager.Total(Model.TotalPractitionerRecords)).Sortable()
.DataBinding(dataBinding => dataBinding.Ajax().Select("PractitionerGridAjaxBinding", "MemberProvider"))
.Columns(columns =>
{
columns.Bound(prac => prac.PractitionerId).ClientTemplate("<input type='checkbox' name='chkPractitioner' value='<#= PractitionerId #>' onclick='handleProviderSelected(this)' />").Width(45).HeaderTemplate(" ");
columns.Bound(prac => prac.LastName).ClientTemplate("<#= LastName #>");
columns.Bound(prac => prac.FirstName);
columns.Bound(prac => prac.NPI);
columns.Bound(prac => prac.SpecialtyName).HeaderTemplate("Specialty");
columns.Bound(prac => prac.Address1).HeaderTemplate("Address");
columns.Bound(prac => prac.City);
columns.Bound(prac => prac.StateCode).HeaderTemplate("State").Width(25);
columns.Bound(prac => prac.PostalCode).HeaderTemplate("Zip Code").Width(25);
columns.Bound(prac => prac.Phone).Width("55");
}).Selectable().ClientEvents(events => events.OnRowSelect("handleOnRowSelect"))
)
According to your code the PCPGrid is not ajax bound:
@(Html.Telerik().Grid(Model.PCP).Name("PCPGrid")
.Columns(columns =>
{
columns.Bound(prac => prac.DisplayName).HeaderTemplate("Name");
columns.Bound(prac => prac.NPI).HeaderTemplate("NPI");
columns.Bound(prac => prac.SpecialtyName).HeaderTemplate("Specialty");
columns.Bound(prac => prac.DisplayAddress).HeaderTemplate("Address");
columns.Bound(prac => prac.Phone).HeaderTemplate("Phone");
}
).ClientEvents(events => events.OnDataBound("PCPGRIDDatabinding")))
function initGridEvents(){
$('a.t-refresh').click(
function(event){
//event.preventDefault();
//Rebind the grid
var grid = $("#PCPGrid").data("tGrid");
grid.rebind({practitionerSpecialty : ''});
}
);
} Greetings,
Atanas Korchev
the Telerik team
You may use onSave client-side event to extend the send values with additional value(s) :
function onSave(e) {
e.values = $.extend(e.values, {foo: "bar"});
}
Rosen
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Thank you for the reply. Adding values in OnSave client event works and I get the values across to the controller update method when the grid is not in the Batch Editing mode. Any idea how the same can be achieved for Batch Editing updates?
Thanks, Venky
In such case you should use SubmitChanges event instead.
Regards,Rosen
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
When I want to rebind the grid, DO i need to create 2 overloaded "indexajax" methods,one with empty parameters and another with the arguments?????????????