Data-binding only part of a DataSource with Kendo UI - javascript

I am using OData and Kendo UI to fetch data, expanding into relations, and presenting them in nested Kendo Grids. Because it seems all of this data is part of one data source, whenever any change happens anywhere in the data, the whole grid is regenerated.
I've reproduced the problem using Northwind data here.
I have a master grid:
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees?$expand=Orders"
},
pageSize: 6,
serverPaging: true,
serverSorting: true
},
height: 550,
sortable: true,
pageable: false,
editable: "inline",
detailInit: detailInit});
and a detail grid with an add button.
function detailInit(e) {
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
data: e.data.Orders.results,
schema: { ... }
},
editable: true,
columns: [ ... ],
toolbar: [{ name: "create", text: "Add Order" }]
});
}
If you expand one of the rows, then click Add Order, the expanded row is immediately collapsed. I've put this down to the entire grid being regenerated.
In Telerik's example this conveniently doesn't happen, a) because they are not editable grids and b) because they are separate endpoints and therefore separate datasources.
Can I force it to only databind the detail grid and prevent this happening?

Related

metronics mDatatable loading problem for huge data 40000 appx..Could not find any solution

metronics mDatatable does not load the table for huge data 40000 appx..so I dont know how to do server side with mdatatable as because mdatatable and datatable is different structure..Please help..
var datatable = $('.m_datatable_event_administrator').mDatatable({
// datasource definition
data: {
type: 'local',
source: resp,
pageSize: 10
},
// layout definition
layout: {
theme: 'default', // datatable theme
class: '', // custom wrapper class
scroll: false, // enable/disable datatable scroll both horizontal and vertical when needed.
// height: 450, // datatable's body's fixed height
footer: false // display/hide footer
},
// column sorting
sortable: true,
pagination: true,
search: {
input: $('#search_event_administrator')
},

How to Get the UID for a Row in Kendo Grid Without Using Grid.Select()

We are building a heads-down data entry application using Kendo, and make heavy use of Kendo Grid. Using selectable='row' or selectable='col' in the grid is problematic because the user is entering data without using the mouse, but navigating the grid using tab key. The visual row/cell selector does not follow the actual active row and cell.
Question: How can I get the row index and/or the uid of the row in the grid with selectable turned off and without using grid.select()?
Here's the grid setup code:
$("#" + target).kendoGrid({
dataSource: gridDs,
edit: gridCellEdit,
height: applet.height,
editable: {
createAt: 'bottom'
},
filterable: true,
sortable: true,
navigatable: true,
resizable: true,
reorderable: true,
scrollable: { virtual: true },
columns: gridColumns,
dataBound: monitorKeyboard
}
});
function gridCellEdit(e) {
var uid = $('#grid_active_cell').closest('tr').data('uid');
console.log(uid);
}
Use whatever means you have at hand to resolve the row element the user is currently on and then simply do:
$(target-tr).data('uid');
If I'm understanding your question correctly, this will be
$('#grid_active_cell').closest('tr').data('uid');
If I misunderstood, please elaborate.
Answer: You can reference the uid field directly using e.model.uid. For example:
$("#" + target).kendoGrid({
dataSource: gridDs,
edit: gridCellEdit,
height: applet.height,
editable: {
createAt: 'bottom'
},
filterable: true,
sortable: true,
navigatable: true,
resizable: true,
reorderable: true,
scrollable: { virtual: true },
columns: gridColumns,
dataBound: monitorKeyboard
}
});
function gridCellEdit(e) {
console.log(e.model.uid);
}

jqGrid - how to delete row from local data?

I am really new to the jqGrid. I'm loading local file (I'm parsing csv file into json and then transfer the array to jqGrid). Table generated through jqGrid should allow user to modify, add and delete the data in the grid. I tried to resolve my problem using various answers from here like:
Adding new row to jqGrid using modal form on client only
There I have found the example made by Oleg for the 4.7 version of jqGrid and reproduced the same code for my purpose. The result was that I am able to delete row which I added after the grid initialisation but I am unable to delete any other row which was loaded from the array.
Another interesting thing is that I am able to modify the rows loaded from array, the only thing I cannot do with the grid is to delete rows loaded from array. I appreciate any advices.
Here is part of the code with jqGrid:
var delSettings = {
onclickSubmit: function () {
var $this = $(this), p = $this.jqGrid("getGridParam"), newPage = p.page;
if (p.lastpage > 1) {// on the multipage grid reload the grid
if (p.reccount === 1 && newPage === p.lastpage) {
// if after deliting there are no rows on the current page
// which is the last page of the grid
newPage--; // go to the previous page
}
// reload grid to make the row from the next page visable.
setTimeout(function () {
$this.trigger("reloadGrid", [{page: newPage}]);
}, 50);
}
return true;
}
};
$("#jqGrid").jqGrid({
datatype: "local",
data: results.data,
editurl: "clientArray",
colModel: [
{
label: 'Id',
name: 'Id',
width: 60,
editable: true,
key: true,
sorttype: 'number'
},
{
label: 'Company',
name: 'Company',
width: 90,
editoptions: {size: 40},
editable: true,
sorttype: 'string'
},
{
label: 'Address',
name: 'Address',
width: 100,
editoptions: {size: 40},
editable: true
},
{
label: 'City',
name: 'City',
width: 80,
editoptions: {size: 40},
editable: true
}
],
height: '100%',
viewrecords: true,
caption: "Baza klientów Klimatest",
pager: "#jqGridPager",
sortable: true,
ignoreCase: true,
cmTemplate: {editable: true, searchoptions: {clearSearch: true }},
rowNum: 5,
rowList: [5, 10, 20],
});
// toolbar searching
$('#jqGrid').jqGrid('filterToolbar', { defaultSearch: 'cn'});
$('#jqGrid').jqGrid('navGrid',"#jqGridPager",
{ edit: true, add: true, del: true, search: true, refresh: true, view: true},
// options for the Edit Dialog
{
editCaption: "The Edit Dialog",
recreateForm: true,
closeAfterEdit: true,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
},
// options for the Add Dialog
{
closeAfterAdd: true,
recreateForm: true,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
},
// options for the Delete Dialog
delSettings,
// options for the Search Dialog
{
},
// options for the View Dialog
{
});
// add first custom button
$('#jqGrid').navButtonAdd('#jqGridPager',
{
buttonicon: "ui-icon-calculator",
title: "Column chooser",
caption: "Columns",
position: "last",
onClickButton: function() {
// call the column chooser method
jQuery("#jqGrid").jqGrid('columnChooser');
}
});
EDIT
Data source is the result of parsed CSV file via Papaparse.js plugin (array of objects), which looks like this:
Id: "100,1"
Address: "Strefowa 8"
Company: "DSSE Sp. z o.o."
City: "Warsaw"
I edited the code just like Oleg suggested and I'm still able to delete only records which are added via interface of jqGrid.
I don't know if it may help, but when I click delete icon and confirm that I want to delete selected row, that row is no longer highlighted, but still visible. Thanks for feedback.
You have clear error in your code near // options for the View Dialog block. The View option should be included after delete and search options (see the documentation). So your current code don't use delSettings options.
I recommend you additionally to include test data in your next questions, because some problems exist only with some specific format of input data.
UPDATED: The problem is in the data which you use. The value for Id which you use contains comma ("100,1"). It's not allowed for jqGrid. First of all id in HTML should not use characters which have special meaning in CSS. The second problem: delGridRow method uses commas in separator to delete multiple rows at once. So the usage of id="100,1" will follows to attempt to delete tow rows: one row with id=100 and the second one with the id=1. By the way I'm developing now jqGrid in my fork of GitHub. I fixed many restrictions with the usage of special characters in ids. So you will be do able to use id="100,1" and successfully delete the rows if you would use jqGrid from my fork.
I recommend you to use underscore if you need to construct id which consist from multiple numbers: Id: "100_1" instead of Id: "100,1".

Implementing a Dependent jqGrid

I have created a jqGrid, and in that I have a column which is a hyperlink, on click, data is fetched and a new jqGrid is created below the parent Grid.
My problem is, that when I click on any link of the parent grid, the child Grid is created successfully. But after that if I click any other link, the child grid shows the same data.
Issue is that the grid is not getting refreshed with the new data.
I have also tried jQuery('grid1').trigger('reloadGrid')
But this also doesn't change anything.
EDIT
*Below is the code which gets called onClick of the element in the Parent Grid:*
var dynaData2 = getDataForWelfareStatusDetails(memberId);
jQuery('#grid1').jqGrid({
datatype: 'local',
data: dynaData2,
colNames:['Effective Date ','Welfare Status ', 'State', 'IV-A/IV-E Case ID', 'Receipt No.','Case Type'],
colMandReq:['-1','-1','-1','-1'],
colModel: [
{ name: 'effectiveDate',index:'effectiveDate', align:"center", editable:false,readonly:true,hidden:false, sortable:false, search: false},
{ name: 'welfareStatus', index:'welfareStatus', align:"center", editable:false,readonly:true,hidden:false, sortable:false, search: false},
{ name: 'stateCode', index:'stateCode', align:"center", editable:false,readonly:true,hidden:false, sortable:false, search: false},
{ name: 'refCaseId', index:'refCaseId', align:"center", editable:false,readonly:true,hidden:false, sortable:false, search: false,formatter: returnCaseLink},
{ name: 'receiptNum', index:'receiptNum', align:"center", editable:false,readonly:true,hidden:false, sortable:false, search: false},
{ name: 'caseType', index:'caseType', align:"center", editable:false,readonly:true,hidden:false, sortable:false, search: false}
],
loadComplete: function()
{
jQuery('#grid1').trigger('reloadGrid');
},
pager: '#pager1',
gridview: true,
rownumbers: false,
autoencode: true,
shrinkToFit: true,
autowidth: true,
sortable: false,
height: '100%',
rowNum: 100,
caption:""
});
Any input is welcome and appreciated
Try this,
jQuery("#grid1")
.jqGrid('setGridParam',
{
datatype: 'local',
data:dynaData2
})
.trigger("reloadGrid");
or you could try with,
jQuery('#grid1').jqGrid("GridUnload");
SEE THIS DOCUMENTATION
First of all about your main problem: Why the grid is not getting refreshed with the new data? The reason is: you try to create the grid #grid1 multiple times. It's wrong. During the first call of jQuery('#grid1').jqGrid({...}); the initial empty <table id="grid1"></table> will be converted to relatively complex structure of divs and tables. The second attempt to create grid from the structure will be just ignored and you don't see refreshing of the grid.
You can fix the code in many ways. The smallest code, but not the best one, you will get if you includes jQuery('#grid1').jqGrid("GridUnload");.
In any way you should remove jQuery('#grid1').trigger('reloadGrid'); from loadComplete of jQuery('#grid1'). The callback loadComplete will be processed during loading or reloading of the grid. So you can have recursion.
Another possibility will be in separation of initial creating of the grid and the later refreshing of the grid content. With the code jQuery('#grid1').jqGrid({...}); you can create the grid. To refresh the data you need 1) delete old data of the grid 2) set new data with respect of setGridParam for example and 3) reload the grid with respect of trigger("reloadGrid").
You don't posted onClick part. I would recommend you to use the approach described in the answer (or this one) which uses beforeSelectRow callback instead of setting multiple click handles.

jQgrid : Disable inline Save and Esc Handler while editing grid Row?

I am developing a asp.net MVC 4 project which uses jQgrid for generating table data.In my generated grid i am providing an inline edit option for particular columns in a row.
My problem is like while editing a particular row if i press Enter or Esc key my selected row is going out of edit mode.
I want to disable those events Enter and Esc .
I googled about this problem and i get some interesting posts How to disable Save Handler on Jqgrid while doing editing
Here in the above reference post i can see that some of the lines are commented out from Jqgrid.src.js file which i dont think as a best solution.
Is there any other method so that i can disable both Enter and Esc Event in Jqgrid while doing inline editing.
Javascript COde
jQuery("#Grid").jqGrid({
url: baseUrl + '/api/Controller/method',
datatype: "json",
mtype: "POST",
colNames: ['Col1', 'Col2', 'Col3', 'Col4', 'Col5'],
colModel: [
{ name: 'col1', index: 'col1', align: 'center', editable: true, key:true },
{ name: 'col2', index: 'col2', align: 'center' },
{ name: 'col3', index: 'col3', align: 'center', editable: true, key:true },
{ name: 'col4', index: 'col4', align: 'center' },
{ name: 'col5', index: 'col5', align: 'center', editable: true, key:true }
],
jsonReader: {
root: 'data',
id: 'col2',
repeatitems: false
},
pager: $('#Pager'),
rowNum: 10,
rowList: [10, 25, 50, 100],
autowidth: true,
shrinkToFit: false,
viewrecords: true,
loadonce: true,
autoencode: true,
multiselect: true,
height: '100%',
width: '100%',
caption: "Record"
});
Sample Grid Structure
Note: Grid Image shown is not the actual grid generated with the above code.
Here in the above grid there are some columns are left editable.My scenario is like i want to put data in all editable column in each row , so that i can update the grid data to server by a button click placed below the grid(Button not shown in the above image).Here i am not using editUrl property of grid.
Currently if i edit first row and accidently if i press enter or Esc key the selected row will become non editable.I want to keep all editable cells in a row as editable untill i press the Submit button placed below the Grid.
My jQgrid Version is 4.5.4
Any help is appreciated.
It's difficult to answer on the question which don't contains neither JavaScript code nor exact references on jqGrid version which you use. You don't describe in which form you use inline editing in the grid.
The usage of Esc and Enter during inline editing can be managed by keys: true option. The exact syntax of the usage of keys option depend on how you use inline editing. For example you can call editRow directly or use some other methods mile inlineNav or the formatter: "actions" which calls editRow for you. The default value of keys option is already false, so you change the value somewhere in your code to true.

Categories