Author Topic: Do not update rows (Batch Editing)  (Read 4382 times)

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Do not update rows (Batch Editing)
« on: October 26, 2017, 01:58:09 pm »
Hello Paramvir,

I wrote in the "Tinyint" column value (55). The server does not write the return value in the column.
Note: added picture

Code: [Select]
function saveChanges() {         
//attempt to save editing cell.
if (grid.saveEditCell() === false) {
return false;
}

if ( grid.isDirty() && grid.isValidChange({ focusInvalid: true }).valid ) {

var gridChanges = grid.getChanges({ format: 'byVal' });

//post changes to server
$.ajax({
dataType: "json",
type: "POST",
async: true,
beforeSend: function (jqXHR, settings) {
grid.showLoading();
},
url: "?isl=GridKaydet", //for ASP.NET, java   
data: {
//JSON.stringify not required for PHP
list: JSON.stringify( gridChanges )
},
success: function (changes) {

//console.log(changes.updateList);

$.each(changes.updateList,function(index, value){
/* ------------------------------------------------------ Hatasız Kayıt */
/*
var rowData = grid.pqGrid("getRowData", {rowIndx: rowIndx});
if (value['PRKOD'] == 0) {
grid.pqGrid("removeClass", {rowIndx: rowIndx,cls: 'ui-state-error'});
var recIndx = grid.pqGrid("option", "dataModel.recIndx");
if (rowData[recIndx] == null) {
rowData[recIndx] = data.recIndx;
}
rowData['TINYINT'] = value['TINYINT'];
grid.commit({ type: 'update', rows: changes.updateList});
grid.pqGrid("commit");
grid.pqGrid("refreshRow", {rowIndx:rowIndx});
}
*/
/* ------------------------------------------------------ Hatasız Kayıt/ */
console.log(index);
$.each(value,function(index, value) {
console.log(index+'/'+value);
});
});

grid.commit({ type: 'update', rows: changes.updateList});
grid.commit({ type: 'add', rows: changes.addList });
grid.commit({ type: 'delete', rows: changes.deleteList });
grid.history({ method: 'reset' });




},
complete: function () {
grid.hideLoading();
}
});
}
}

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Do not update rows (Batch Editing)
« Reply #1 on: October 26, 2017, 05:08:44 pm »
What's the purpose of $.each(changes.updateList,function(index, value){....}) loop which is not there in the example:

https://paramquery.com/pro/demos/editing_batch

and please share dataModel and colModel.

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: Do not update rows (Batch Editing)
« Reply #2 on: October 26, 2017, 05:26:31 pm »
Hello,

I wrote "$ .each" to check the returned values.

Then I control on the "chrome-> network" tab.

dataModel
Code: [Select]
dataModel: {
dataType: "JSON",
method: "GET",
location: "remote",
recIndx: "ID",
url: "?isl=GridGetir",
getData: function (response) {
var data=response.data;
return { curPage: response.curPage, totalRecords: response.totalRecords, data: data };
}
}

pageModel
Code: [Select]
pageModel: {
type: "remote",
curPage: 1,
rPP: 25,
rPPOptions: [1, 5, 10, 15, 25, 50, 100, 200]
},

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Do not update rows (Batch Editing)
« Reply #3 on: October 27, 2017, 12:03:30 am »
Preview tab is for response from the server. Grid doesn't control response from the server.

What is the form data posted by grid? it can be seen at the bottom of Headers tab.

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: Do not update rows (Batch Editing)
« Reply #4 on: November 10, 2017, 02:11:12 pm »
Hello,

1) I'm typing 3 on the "TINYINT" column from the grid and I'm press on the record button.

2) I'm server side. If the sample TINYINT is small, I return 25 as 100.
Example-1) I am checking on the server side (sql), I am writing 2 changes the user writes when writing 4 pieces.
Example-2) The user writes 25/1 to the grid and I check it on the server side. I write it as 25/01/2017.

3) The incoming response does not change the values in the grid.
https://www.youtube.com/watch?v=PLprOivsL_Y&feature=youtu.be

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Do not update rows (Batch Editing)
« Reply #5 on: November 10, 2017, 09:55:52 pm »
The incoming response is not supposed to change the values, it's only for confirmation to commit the matching rows.

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: Do not update rows (Batch Editing)
« Reply #6 on: November 11, 2017, 01:17:07 am »
I understand.

"grid.commit ({type: 'update', rows: changes.updateList});" after the line "grid.refreshDataAndView ();" I've write. I see the current data.

"Grid.refreshdataandview ();" instead of "grid.pqGrid (" refreshRow ", {rowIndx: rowIndx});" can I use? Just to get updated 2 lines

I suppose I need to reach "rowIndex" for "changes.update List"
Code: [Select]
//post changes to server
$.ajax({
dataType: "json",
type: "POST",
async: true,
beforeSend: function (jqXHR, settings) {
grid.showLoading();
},
url: "?isl=GridIslem", //for ASP.NET, java   
data: {
list: JSON.stringify(changes)
},
success: function (changes) {
grid.commit({ type: 'add', rows: changes.addList });
grid.commit({ type: 'update', rows: changes.updateList });
grid.commit({ type: 'delete', rows: changes.deleteList });
grid.history({ method: 'reset' });
//grid.pqGrid("refreshRow", {rowIndx:rowIndx});
grid.refreshDataAndView();
},
complete: function () {
grid.hideLoading();
}
});
« Last Edit: November 11, 2017, 01:26:58 am by omerix »

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: Do not update rows (Batch Editing)
« Reply #7 on: November 11, 2017, 04:24:15 am »
Hello Param,

This code solved my problem.

Video: https://youtu.be/9b5bhFIbbUM

But there is a lot of work. You will need to equal each column name.
rd['COLUMN1'] = response.addList[index].COLUMN1;
rd['COLUMN2'] = response.addList[index].COLUMN2;
rd['COLUMN3'] = response.addList[index].COLUMN3;

etc...


Code: [Select]
function saveChanges() {
//attempt to save editing cell.
if (grid.saveEditCell() === false) {
return false;
}

if (grid.isDirty() && grid.isValidChange({ focusInvalid: true }).valid) {
var changes = grid.getChanges({ format: 'byVal' });

//post changes to server
$.ajax({
dataType: "json",
type: "POST",
async: true,
beforeSend: function (jqXHR, settings) {
grid.showLoading();
},
url: "?isl=GridIslem", //for ASP.NET, java   
data: {
list: JSON.stringify(changes)
},
success: function (response) {
/*
$.each(response.updateList,function(index, value){
console.log('update'+index);
$.each(value,function(index, value) {
console.log(index+'/'+value);
});
});
*/
var ri; //rowIndex
var rd; //rowData
var postChanges = grid.getChanges();

$.each(postChanges.addList,function(index, value){
ri=value.pq_ri;
console.log('ADD/rowIndex='+ri+',Changes Tinyint='+value.TINYINT+',Response Tinyint='+response.addList[index].TINYINT);
grid.addClass({rowIndx: ri, cls: 'pq-striped-error'});
rd = grid.getRowData({rowIndx: ri});
rd['ID']=response.addList[index].ID;
rd['TINYINT'] = response.addList[index].TINYINT;
grid.refreshRow({rowIndx:ri});
})


$.each(postChanges.updateList,function(index, value){
ri=value.pq_ri;
console.log('UPDATE/rowIndex='+ri+',Changes Tinyint='+value.TINYINT+',Response Tinyint='+response.updateList[index].TINYINT);
grid.addClass({rowIndx: ri, cls: 'pq-striped-error'});
rd = grid.getRowData({rowIndx: ri});
rd['TINYINT'] = response.updateList[index].TINYINT;
grid.refreshRow({rowIndx:ri});
})

grid.commit({ type: 'add', rows: response.addList });
grid.commit({ type: 'update', rows: response.updateList });
grid.commit({ type: 'delete', rows: response.deleteList });
grid.history({ method: 'reset' });
},
complete: function () {
grid.hideLoading();
},
error: function (jqXHR, textStatus, errorThrown) {
$('<div></div>').html('<a Onclick="$(\'#errorTam\').toggle();" title="Tam hatayı göster">Hata Kodu:' + jqXHR.status + ' (Hata Açıklamasını Göster)<br>' + jqXHR.statusText + '<br></a><div style="display:none;" id="errorTam">' + jqXHR.responseText + '</div>').dialog({
position: ['center', 'top'],
modal: true,
zindex: 9002,
title: textStatus
,close: function( event, ui ) {
}
});
}

});
}
}


The incoming response is not supposed to change the values, it's only for confirmation to commit the matching rows.