Treeview select event is not firing in kendo ui - kendo-ui

I have a treeview defined like
$("#treeview").kendoTreeView({
dataSource:homogenous,
dataBound: function(e){
$("#treeview").data("kendoTreeView").select(".k-item:first");
},
select: function(){
alert('selectd');
}
});
Initially the treeview is selecting. But it is not getting the alert of select. But when we selecting the node it is getting the alert. How should i get rid of them.

The select method won't fire the select event. You can however use the trigger method to fire any event:
dataBound: function(e){
$("#treeview").data("kendoTreeView").select(".k-item:first");
$("#treeview").data("kendoTreeView").trigger("select", {
node: $("#treeview .k-item:first")[0]
});
},

Related

Prompting user before paging Kendo grid

Is there a way I can create something like a "are you sure?" when the user tries to page a kendo grid.
However, there is no event like "beforePaging" or something.
I found this question with the exact same issue but the answer there doesn't do anything for me (using requestStart).
I tried to add an event listener for the paging buttons and it went ok, but I can't cancel the paging event as it is not directly bound to the paging:
$(document).on("click", ".k-pager-numbers li a", function (e) {
e.preventDefault();
alert("Handler for .click() called");
});
The above is called, but the preventDefault doesn't prevent paging, as e is not the actual paging event.
There is now good or proper way for this, but you can use code below. Put in on DataSource requestStart event.
requestStart: function(e) {
if (e.type == "read" && this.hasChanges()) {
if (confirm("You need to fill information before...") == false) {
e.preventDefault();
e.stopPropagation();
}
}
},

Listen to sub-sub views in Backbone Marionette

I have a collection view, and each item view is a composite view, which also has a item view. I want to listen to the events from this last (sub-sub) item view.
View.Block = Marionette.Layout.extend({
triggers: {
'click .content': 'block:click'
}
});
View.Category = Marionette.CompositeView.extend({
itemView: View.Block
});
View.Categories = Marionette.CollectionView.extend({
itemView: View.Category
});
In my controller I only have a reference to View.Categories:
var categories_view = new View.Categories({
collection: categories
});
Is it possible to listen to click events from View.Block using Marionette's built-in view events? I tried categories_view.on('itemview:block:click') but that won't work as View.Block isn't an item view of View.Categories, but of View.Category.
You'll need to use a module- or application-level event aggregator to achieve your objective:
events: {
"click .something": "triggerEvent"
},
triggerEvent: function(e){
myApp.trigger("something:clicked", e);
}
(myApp is the instance of your Marionette application.)
Then listen for that event:
myApp.on("something:clicked", function(e){
e.preventDefault();
console.log("something was clicked");
});

kendoUI grid-command-click-event-triggered-multiple-times

I have a KendoUI grid presented in a mobal window (kendoWindow). The grid has a column command with a click event:
$("#grid").kendoGrid({
...
columns:[
...
{ command: { text: "Delete", click: ContactDelete }],
}];
This delete Command Button is calling the method multiple time as much as rows are there in the grid,means if we have 1 rows in the grid then once ,2 rows it will call twice and so on also I'm having problem of rebinding the grid after deleting the rows,Even i tried with grid.destroy and lot other options.
Sample Code Here
create custom events like below and onclick event call a function ...
command.Custom("Edit").Text(" ").Click("EditRole");

kendo treeview head node from child

I have a kendo treeview i use this function to bind event change
change: function (e) {
if (e.field == "checked") {
gatherStates(e.items);
alert(e.items);
}
}
If i want to know the 'dad node'(the node that contain the selected child) of the selected child?
You can get the parent node from e.node:
tree.dataSource.bind("change", function (e) {
if (e.field == "checked") {
var node = e.items[0];
console.log("node", node.text);
console.log("parent", e.node.text);
}
});
Example here (http://jsfiddle.net/OnaBai/ECnef/)
i have a same kind of issue with kendo treeview checkboxes in IE8
jQuery("#treeview").kendoTreeView({
dataSource: ss,
dataTextField: ["ss_"],
checkboxes: {
checkChildren: true
},
select: function (e) {
jQuery(e.node).find("input")[0].click();
}
});
var treeview = jQuery("#treeview").data("kendoTreeView");
treeview.expand(".k-item");
treeview.dataSource.bind("change", onCheckboxClicked);
selecting the text of checkbox fires the select event of treeview and in this event i click the checkbox manually (my requirements)...which in turn fires change event of data source in IE-9. But it doesn't fire the change event of datasource in IE-8. What is the issue?
Thanks

Kendo Grid cancel edit event

I'm using the edit event on a Kendo grid to show a couple of hidden columns. I'll then hide them again on the save event.
Problem I have is that there doesn't appear to be an event for cancelling edit mode, so the column get screwed up if the user clicks cancel.
Is there an undocumented event for cancel or do I need to find a workaround?
Basically there is no such "Cancel" event, however you can attach click event on the "Cancel" button in the еdit event of the Grid. Please check the example below:
function onEdit(e) {
e.container.find(".k-grid-cancel").bind("click", function () {
//your code here
})
}
EDIT: From some time the Grid have "cancel" event which can be used instead of the above solution:
cancel event
I've been looking for an answer to the same question but this didn't work for me. I had a scenario where new and edited records within my grid are validated within my controller and error messages are added to the ModelState's ModelError collection. I had hooked up the grid's datasource error event which then displayed the error message within an alert, and then added the following which reset the changes:
$('#MyGrid').data("kendoGrid").cancelChanges();
It was a neat solution for me because I am using paging and the current page the user is viewing is preserved.
Contrary to what the accepted answer states there is in fact a cancel event just like the edit event.
$("#grid").kendoGrid({
...
edit: function(e) {
alert("edit")
},
cancel: function(e) {
alert("cancel");
},
...
});
Try this,
$("#grid").kendoGrid({
columns: [
{ field: "name" },
{ field: "age" }
],
dataSource: [
{ name: "Jane Doe", age: 30 },
{ name: "John Doe", age: 33 }
],
dataBound: function(e) {
$("#grid").on("mousedown", ".k-grid-cancel-changes", function (e) {
//custom logic
});
}
});
In dataBound, wire click event for the kendo grid Toolbar cancel button. It will work.

Resources