Hi - I'm hoping you can help me with some issues I'm having. I am using the the autosave demo as a foundation. My "change" functionality is below. For some reason I am having trouble adding a row - editing and deleting work. It seems to be adding the row after all required fields are entered, but it does not clear the small red triangle in the corners after the item is successfully saved in the database. I am also unable to add another row because of a "duplicate primary key" error. I was unable to add a row to the top of the grid because it would always enter data in the fields instead of blank fields even when I fully defined every field to be blank in the addRow function.
Please let me know how I need to update this to make the add work.
Change function:
-------------------------------------------------------------------
change: function (evt, ui) {
//debugger;
if (ui.source == 'commit' || ui.source == 'rollback') {
return;
}
console.log(ui);
var $grid = $(this),
grid = $grid.pqGrid('getInstance').grid;
rowList = ui.rowList;
var obj = rowList[0],
rowIndx = obj.rowIndx,
newRow = obj.newRow,
type = obj.type,
rowData = obj.rowData,
url,
recIndx = grid.option('dataModel').recIndx;
if (grid.saveEditCell() == false) {
return false;
}
var isValid = grid.isValid({ rowIndx: rowIndx }).valid;
if (!isValid) {
return false;
}
if (grid.isDirty()) {
if (rowData[recIndx] == null || rowData[recIndx] == '' || rowData[recIndx] == 0) {
//add record.
$.ajax( {
url: "/cfc/Testing.cfc?method=insertMatrix",
data: "rowData=" + escape(JSON.stringify(rowData)),
beforeSend: function (jqXHR, settings) {
$(".saving", $grid).show();
},
success: function (response) { // returns response as id of new record created
rowData[recIndx] = response;
grid.commit({ type: 'add', rows: [rowData] });
grid.refreshRow({ rowIndx: rowIndx });
},
complete: function () {
$(".saving", $grid).hide();
},
error: function(jqXHR, exception){
alert('closing - change - update row - ' + jqXHR.responseText + ":" + exception);
}
});
} else if (type == 'delete') {
var ans = window.confirm("Are you sure to delete '" + rowData['itemid'] +"'?");
if (ans) {
var moveid = $grid.pqGrid("getRecId", { rowIndx: rowIndx });
grid = $grid.pqGrid('getInstance').grid;
if (itemid != null && itemid != 0) {
$.ajax( {
url: "/cfc/Testing.cfc?method=deleteMatrix",
data: "rowData=" + escape(JSON.stringify(rowData)),
beforeSend: function (jqXHR, settings) {
$(".saving", $grid).show();
},
success: function (response) {
grid.commit({ type: 'delete', rows: [rowData] });
grid.refreshRow({ rowIndx: rowIndx });
},
complete: function () {
$(".saving", $grid).hide();
},
error: function(jqXHR, exception){
alert('closing - delete row - ' + jqXHR.responseText + ":" + exception);
}
});
}
}
else {
$grid.pqGrid("removeClass", { rowIndx: rowIndx, cls: 'pq-row-delete' });
}
} else {
type = 'update';
$.ajax( {
url: "/cfc/Testing.cfc?method=updateMatrix",
data: "rowData=" + escape(JSON.stringify(rowData)),
beforeSend: function (jqXHR, settings) {
$(".saving", $grid).show();
},
success: function (response) {
if (type == 'add') {
rowData[recIndx] = response.moveid;
}
grid.commit({ type: type, rows: [rowData] });
grid.refreshRow({ rowIndx: rowIndx });
},
complete: function () {
$(".saving", $grid).hide();
},
error: function(jqXHR, exception){
alert('closing - change - update row - ' + jqXHR.responseText + ":" + exception);
}
});
}
} else {
grid.quitEditMode();
grid.removeClass({ rowIndx: rowIndx, cls: 'pq-row-edit' });
grid.refreshRow({ rowIndx: rowIndx });
}
}
----------------------------------------------------------------------------------------
--------------------------------------------------
Latest AddRow attempt
--------------------------------------------------
--------------------------------------------------------------------------------------
{ type: 'button', icon: 'ui-icon-plus', label: 'Add Inject', listener:
{ "click": function (evt, ui) {
//append empty row at the end.
var rowData = { namefield: '' }; //empty row
var rowIndx = $grid.pqGrid("addRow", { rowData: rowData });
$grid.pqGrid("setSelection", null);
$grid.pqGrid("setSelection", { rowIndx: rowIndx, dataIndx: 'moveid' });
$grid.pqGrid("editFirstCellInRow", { rowIndx: rowIndx });
}
}
},
--------------------------------------------------
TIA,
Angela Jones