So my question to the Development Team for MVC Extensions, especially the Grid, will there be support for enabling extensibility of the Telerik Grid using Knockout?
Please offer any comments... Thanks!
8 Answers, 1 is accepted
I am sending a sample project showing how to use the input components (DateTimePicker and NumericTextBox) with KnockoutJS (there is some JavaScript required).
As for the grid could you share with us what kind of support you mean? The grid editing is done by the grid itself - it tracks the changes of the model internally without the need of a third party JavaScript library.
Atanas Korchev
the Telerik team


Note that I'm using ASP.NET rather than the MVC framework...
I based my code from the example posted above.
<telerik:RadDatePicker ID="RadDatePicker1" runat="server" data-bind="value: fromDate">
<ClientEvents OnDateSelected="DatePicker_DateSelected" />
<DateInput runat="server" data-bind="value: fromDate"/>
</telerik:RadDatePicker>
and...
function DatePicker_DateSelected(sender, e) {
$(sender.get_textBox()).val(sender.get_dateInput()._initialValue);
$(sender.get_textBox()).trigger("change");
};
Does anyone have similar experiences or suggestions as to how to avoid this somewhat "hacky" way of doing things?
If you would like to see more code to support the above sing out and I will put together an example but this should hopefully be enough to see what I'm doing.
Thanks!

ko.bindingHandlers.date = {
init:
function
(element, getValue) {
var
datePicker = getDatePicker(element),
dateObservable = getValue();
datePicker.add_dateSelected(
function
(sender, args) {
dateObservable(args.get_newDate());
});
},
update:
function
(element, getValue) {
var
datePicker = getDatePicker(element),
dateValue = ko.utils.unwrapObservable(getValue());
datePicker.set_selectedDate(dateValue);
}
};
The getDatePicker function is hardcoding the ID. You could probably add the client ID to the control's attributes collection, and use that instead of hardcoding there.
getDatePicker =
function
(datePickerParentElement) {
return
$telerik.findControl(datePickerParentElement,
'SpecificDatePicker'
);
}
Hope that helps someone.
I've also tried doing this on the RadNumericTextBox, but when I add the data-bind attribute there, it doesn't go on the wrapper, so I probably will need to adjust how I'm getting the client-side control for that case.

I'm doing something with an additional twist -- the Telerik control (in this case, a DropDownList) -- is loaded after initial page load via Ajax. I have to make a specific ko.applyBindings() call with the pertinent ViewModel and the newly created DOM element. Everything works great except for the initial selected value, I'll have to figure it out.


