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.
Related
Is it possible to prevent a kendo combobox from opening it's popup when the user is typing text? I still want allow the user to click on the arrow button. The open event can prevent the popup from opening but there's no way to know what triggered the event.
$("#customers").kendoComboBox({
dataTextField: "ContactName",
dataValueField: "CustomerID",
//delay: 999999, WORKAROUND #1
//enforceMinLength: true, WORKAROUND #2
//minLength: 999999, WORKAROUND #2
dataSource: {
type: "odata",
transport: {
read: "..."
}
},
open: function (e) {
//Triggered by user click or by user input?
if (triggeredByUserInput) {
e.preventDefault();
}
}
})
The only workarounds I've found so far is to set a very long delay or to enforce the minLength with a long length. While they both work, I think it's a very odd way to fix the problem in the first place so I was wondering if there was a more specific solution.
The open event still provides a reference to the original event, so you can check if the user clicked on the arrow button or not - example:
open:function(e) {
if(!$(event.target).hasClass("k-button-icon")){
e.preventDefault();
}
}
or even
open:function(e) {
if(!(event.type == "click")){
e.preventDefault();
}
}
I've noticed that my custom Grid command is not working after a popup edit dialog is opened and closed (cancelled).
The command delrow is used to display a custom delete confirmation (I've simplified it in the fiddle to just use a standard JS confirmation).
I've setup a Fiddle that demonstrates the problem.
It works when the grid is initially loaded, but not after a cancelled edit. Not sure if this is a bug or something I'm doing wrong.
Any advice would be much appreciated. Thanks
Is the way you do it. You are binding the click event in the dataBound but when you cancel the edition the row is refreshed and you loose the bind.
You should define the action using click property as:
columns : [
{
command: [
{name: 'edit'},
{name:'delrow', click: delRow}],
title: ' ',
width: 100
},
{ field: "FirstName", width: 90, title: "First Name" },
...
Where delRow is the same code that you have as click event handler:
function delRow(e) {
var row = $(this).parents('tr:first');
var r=confirm("Are you sure you want to delete this row!");
if (r==true)
{
var g = grid.data('kendoGrid');
g.removeRow(row[0]);
}
}
See it in action here : http://jsfiddle.net/OnaBai/XNcmt/56/
I have run into an issue with the kendo-ui grid that I can't solve. In my application I am using kendo-grid in batch edit mode to allow a data entry person to quickly make edits to several records on a screen. This particular grid is set to allow paging and sorting.
I am looking for a way to prompt the user upon attempting a sort or clicking on one of the paging links while there have been edits made on the particular page (as in page of the datagrid/datasource). If the user clicks OK, then I want to continue onto the next page of data, otherwise I would like to cancel the edit and keep the user on the current page with the existing edits. My other option would simply be to automatically commit any changes upon paging or sorting or allow them to cancel and stay on the current page.
My attempts thus far have been to use the change event on the actual grid datasource to store a dirty flag into an observable and then try to catch the actual sorting or paging change by listening to the dataBinding event of the grid and display the prompt when my isDirty flag is true and the e.action of the dataBinding event == "rebind".
The problem that I am having with this approach is that the dataBinding event fires after the grid dataSource has already performed a fetch of another page and not prior. This prevents me from both saving any edits or even maintaining existing edits.
I can't find any event that I can subscribe to that will allow me to do inspections prior to a page fetch/sort. Has anyone else come up with a way to handle this scenario? It seems to me that it would be a pretty common thing that people would want to handle in data entry applications.
I solved my problem by subscribing to the requestStart event of the dataSource. So now my Kendo Datasource looks like this:
{
pageSize: 15,
batch: false,
schema: {
model: {
id: "LocalId",
fields: {
LocalId:
{
editable: false,
nullable: true
},
Ssn: {
validation: {
required: true
}
},
QtrEarnings: {
type: "number",
defaultValue: 0,
validation: { required: true, min: 0 }
}
}
}
},
change: function (e) {
onDataChange(e);
},
requestStart: function (e) {
if (homeModel.get("dataSource").hasChanges()) {
if (confirm("You have made edits to data! Click Cancel to stay on this page or click Ok to abandon your changes and continue.") == false) {
e.preventDefault();
}
}
}
}
I want to write code on Refresh button click of JQGrid. Is there any event for that?
If you need to do some actions before refresh will be started you should use beforeRefresh callback:
$("#grid_id").jqGrid('navGrid', '#gridpager', {
beforeRefresh: function () {
// some code here
}
});
If you need absolute another implementation of grid Refreshing where you will not call $("#grid_id").trigger("reloadGrid"); (which sound strange) you can do this by the usage of refresh: false option to remove the standard Refresh button and using navButtonAdd to add your custom button which looks exactly like the original one:
$("#grid_id").jqGrid('navGrid', '#gridpager', {refresh: false});
$("#grid_id").jqGrid('navButtonAdd', "#gridpager", {
caption: "", title: "Reload Grid", buttonicon: "ui-icon-refresh",
onClickButton: function () {
alert('"Refresh" button is clicked!');
}
});
The css for refresh button is ui-icon-refresh
so you can write your custom code on this css like
jQuery('.ui-icon-refresh').click(function(){
// do your work
});
I'm having some trouble with blur and click events in backbone. I have a view (code below) that creates a little search entry div with a button. I pop open this div and put focus on the entry field. If someone clicks off (blur) I notify a parent view to close this one. If they click on the button I'll initiate a search.
The blur behavior works fine, however when I click on the button I also get a blur event and can't get the click event. Have I got this structured right?
BTW, some other posts have suggested things like adding timers to the div in case its being closed before the click event fires. I can comment out the close completely and still only get the blur event. Do these only fire one at a time on some kind of first-com-first-served basis?
PB_SearchEntryView = Backbone.View.extend({
template: _.template("<div id='searchEntry' class='searchEntry'><input id='part'></input><button id='findit'>Search</button></div>"),
events: {
"click button": "find",
"blur #part": "close"
},
initialize: function(args) {
this.dad = args.dad;
},
render: function(){
$(this.el).html(this.template());
return this;
},
close: function(event){ this.dad.close(); },
find: function() {
alert("Find!");
}
});
I am not sure what the problem was, but here is the jsbin code.