Prevent combobox popup when user is typing - kendo-ui

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();
}
}

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();
}
}
},

Prevent hiding for cytoscape qtip

I'm using the Cytoscape Qtip extension to display qtips when you click nodes.
Usually you can prevent qtips from hiding when with the hide: false option. When this is used, you can still hide the qtips if it has a button.
However, when using cytoscape, this appears to not work. When clicking else where, a hide event will be triggered.
cy.elements().qtip({
content: function(event, api){
api.set('content.button', true);
return 'Example qTip on ele ' + this.id();
},
position: {
my: 'top center',
at: 'bottom center'
},
hide: false,
style: {
classes: 'qtip-bootstrap',
tip: {
width: 16,
height: 8
}
}
events: {
hide: function(event, api){
console.log(event);
}
}
});
I can prevent the hide event from following through with event.preventDefault(), but this will also stop the the close button from hiding the event, which is a bit messy.
Any idea while it's behaving this way?
Here's the quick and dirty to make this work (closes on button close only) if you need it:
events:{
hide: function(event, api){
if(event.originalEvent.target.parentElement.parentElement.id != this[0].id){
event.preventDefault();
}
}
Explanation:
Any mouse clicks will trigger a hide event all visible qtips.
We look at target of that mouse click (event.originalEvent.target.parentElement.parentElement.id) to see it close box of the qtip that is currently try to close. If it's not then we preventDefault().
This is potentially pretty bed performance wise, because it run these preventDefault() for every open qtip on every mouse click.
Remember that because this wraps Qtip on non-DOM elements, bindings to Cytoscape graph elements must be made. These bindings are outside of the DOM and outside of Qtip's control (for example, the hide case).
Did you try setting the hide event to the empty string ""?
Cleanest solution I've found is to give a garbage event for the hide event.
Using null, false or "" all don't seem to work.
hide: {
event: "asdf" //garbage event to allow hiding on close button click only
},

How to prompt user that edits have been made upon changing pages or sorting in Kendo Grid

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();
}
}
}
}

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.

JQgrid on refresh button click

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
});

Resources