I have a requirement to use a custom button for inserting new data for the datagrid.
There are several grids per page, named dynamically...for example: grid39, grid40, grid41
For various reasons, I have to use an outside control for adding records via ajax. In the result handler, I have to add the returned data to the dataSource and then refresh the data or better yet, just refresh the data. Either one will work. The ajax call is from a select's onChange event...here is the code:
function estimate_item_Onchange(id){
console.log("OK, estimate item selected.");
var estimate_item_id = $('#estimate_item' + id).val();
console.log(estimate_item_id);
//hide select
$($('#estimate_item' + id)).hide();
//reset select options
$('#estimate_item').val("");
let areaId = id;
console.log(areaId)
let data = {estimateItemId: estimate_item_id, areaId: areaId};
//get the CSRF token
let csrfToken =$('[name = "_token"]').val();
$.ajax({
url: '/assigned_estimate_items/post',
type: 'POST',
data: {_token: csrfToken, data: data},
dataType: 'JSON',
success: function (data) {
var area_id = data.data.areaId;
var record = data.data;
var gridname = 'grid' + area_id;
console.log(grid39);
console.log(grid39.dataSource);
console.log(gridname);
console.log(gridname.dataSource);
gridname.insert(record);
},
error: function (e) {
console.log('error message'.e);
}
});
}
So
I have tried several different avenues, but the error is always some version of:
2:1033 Uncaught TypeError: gridname.insert is not a function
at Object.success (2:1033)
at c (jquery-3.4.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.4.1.min.js:2)
at l (jquery-3.4.1.min.js:2)
at XMLHttpRequest.<anonymous> (jquery-3.4.1.min.js:2)
Part of the problem might be that the grid name has to be 'built'...but I get the same error even with using
the grid's name directly (which of course I can only do during development).