KendoUI Grid - rollback from from a remove row - kendo-ui

I am creating a custom transport for KendoUI that would connect Kendo to a number of cool data sources like webSQL. My Kendo Grid problem is that when I implement the delete/destroy command I am not able to prevent the grid from the actual remove row to happen, even if the data source layer has responded with an error.
I get called via the RemoteTransport.destroy method. The input parameter contains an error and a success callback, but even if I call the error callback, or try to return a "false", or try to return a $.Deferred that I eventually reject: the grid row is gone. Actually it's gone before I get called.

I believe you would want the cancelChanges method on the grid.
http://docs.kendoui.com/api/web/grid#cancelchanges
A response from the KendoUI forum helps decoupling the UI part from the data layer part
In the RemoteTransport
call the rejection handler this will cause an exception in the
DataSource. In the DataSource definition place an error handler that
call the actual cancelChanges or whatever rollback method the control
will have. Still inperfect - but at least doable.

Related

How to access to my Grid in Dynamic CRM365 View

I am working on Dynamic CRM365 plugin, in my entity view, I need to know which item has been selected, before I use DOM to detect, however, I can't pass the certification, because all DOM access are risk and need to be replaced, therefore, I checked Xrm.Page.getControl and Xrm.Page.ui.controls, but no luck.
I passed Xrm.Page.getControl("ssl_notesforsigns") or Xrm.Page.getControl("ssl_notesforsign") => return null
I call Xrm.Page.ui, ui = null.
Any idea how to get grid by code?
Thanks
It is good to hear that you no longer want to access the DOM. As you say, that is entirely unsupported.
What is the name of the subgrid on your form? If you go to a form editor and look at the properties for the subgrid, you will see the name (I am guessing that it is not called ssl_notesforsigns). This name is the one you should use, and it can be used when calling Xrm.Page.getControl("namehere") to get your grid context.
Xrm.Page has been deprecated (even though you can still use it). Instead, you should get a reference to your grid context through the execution context. See Client API grid context. For code executing on a form event, you can get your grid context through the form context as follows:
var formContext = executionContext.getFormContext(); // get the form Context
var gridContext = formContext.getControl("namehere"); // get the grid context
When you have a reference to your grid context, you can get the selected rows using getSelectedRows():
var allSelectedRows = gridContext.getGrid().getSelectedRows();

Kendo Grid: Clearing filter without calling server side read of data

I have a kendo grid with server side paging. On the same page, I also have a clear button which should clear the data of the grid and replace it with blank rows. Is it possible to clear the filters of that grid, without calling the server side read? Currently when I do this, $("#grid").data("kendoGrid").dataSource.filter({}), it will call the server side function and load the data. Anyone can point me to the right direction? Thanks.
Despite serverFiltering set to false by default, it seems that filter() automatically calls transport read every single time.
However, you can try this:
dataSource._filter = null;
This will cancel any filters applied to the dataSource without calling transport read. But, you have to be cautious with this approach as it isn't an "official" configuration documented by Telerik. The property _filter is internal, so to speak.
You can verify this works by console logging the requestEnd event and seeing that this doesn't make a request.

Devexpress detail gridview events not firing

I have a master "gridview" and a detail "gridview" connected to it. The detail "gridview" does not have any columns initially, it loads data from database and it creates its columns.
For example, i'm trying to handle cellvaluechanged event, however, even if i write something in a cell of the gridview and then pressing enter, the event is not firing. What can the reason be?
In my opinion the best way to handle this is: Create a class which represent the data from your database. Let the class implement the interface INotifyPropertyChanged. Then create a BindingList with all Objects from your Database. Now use this BindingList as DataSource for your Grid. The BindingList got the Event ListChanged. This will recognize that a Property Value in your DataSource is changed if you type some new value in cell.
I think this is best practice because you are working with your DataSource and not with GridView directly.
Otherwise the event should fire for sure. If you cant use my idea send some code, maybe i can find the problem then.
regards

Kendo UI Cascading Combobox - Check if initialised

I am using the Kendo UI Cascading combo boxes in an MVC 4 application. The source is too complex to post here, however it follows exactly the same structure as the MVC demo on the Kendo UI site (http://demos.kendoui.com/web/combobox/cascadingcombobox.html).
Occasionally I am getting the exception below, I assume this is because the page isn't fully loaded and the user has tried to interact with the page, therefore causing the combo to attempt to submit an AJAX request to get it's data.
Microsoft JScript runtime error: Cannot call method 'value' of kendoDropDownList before it is initialized
Is there a correct way of checking whether Kendo controls are fully initialised ? If not how can I catch this exception ?
Thanks, Jon.
Make sure load the combo box before you call
var val = $("#yourCombobox").value();
if your combobox isn't initialize it gives undefined as the result.
Load the main combo at the $(document).ready() function and then the onchange even of that combo get the value and load the next combo.

Kendo Grid - How to stop or prevent Databound event

I have Kendo grid as empty. Then I add one row, entering values and call saveRow() method. This will call controller and returns message, based on message I want to clear added(newly) record. I have used the code is: grid.dataSource.data([]); this code calling data bound event two times. I want this to be called only ONCE or I don't want to call Data bound event.. but I have to empty the grid.
Please advise.
Hello you can try and use the requestEnd event of the dataSource - check that message which you return, prevent the next dataBinding of the Grid and set the data again to empty array.
e.g.
function onRequestEnd(e){
if()//some condition basedo on the e.response
{
$('#grid').data().kendoGrid.one('dataBinding',function(e){
e.preventDefault();
this.dataSource.data([]);
})
}
}
You could add a filter to your datasource. Make it so that it filters away everything that the server sends it and you should be able to get the behaviour that you are looking for. Then you wont have to mess about with events too much or delete rows manually.
This page contains some info about filtering datasources: kendo datasources
Hope this helps!

Resources