Author Topic: Cell Edit and Save,Return info  (Read 4656 times)

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 147
    • View Profile
Cell Edit and Save,Return info
« on: November 24, 2013, 04:23:58 pm »
Hello ,

 

1)      I am trying to post the AJAX just after  I use up and down arrow keys. But I got "evt.keyCode" "undefined" and therefore it does not run if clause.

 

2)      Meanwhile lets say user edited two cells. Although user edited 2 cells I would like to set new value into additional 2 cells more according to the cells edited. Can I do this using the value return from AJAX assigning the "new json data" data of the line?

 

3)      When user makes an invalid entry while editing a cell, I would like to  post it with AJAX and I would like to Show the error message like "process:error" after checking the server error. Can I do this? The reason why I want this, because I remember a sample showing the error very nicely then change the shape of the cell and it prevent user to out of it. In my application there is a warehouse and if user orders more quantity of goods than what they have in stock, there must be an error message.

 

SAMPLE on setting value:

There is way of shipment information in 2nd cell. It is "Express,Normal", Price information is on 4th cell.

If user picks "Express" on 2nd cell just after it is recorded, if I assign a value as ben {"COL1:"="Express","COL4"="15 USD"}  on "PQGrid.asp?isl=Save", can PqGrid set this?

 

 


editModel
Code: [Select]
    ,editModel: {
        clicksToEdit: '1',
            saveKey: $.ui.keyCode.ENTER,
            select: false,
            keyUpDown: true,
            cellBorderWidth: 0             
        }

Save Code
Code: [Select]
/* *********************************************************************************************************** */
  $grid.on( "pqgridcellsave", function( evt, ui ) {
    var rowData = $grid.pqGrid( "getRowData", {rowIndx: ui.rowIndx} );
    var oldVal= ui.oldVal;
    var newVal= ui.newVal;
    var keyCode=evt.keyCode;
alert(keyCode);
    var json_arr = JSON.stringify({
      action: 'update'
      ,grid_id: 'grid_search'
      ,rowIndx: ui.rowIndx
      ,rowIndxPage: ui.rowIndxPage
      ,colIndx: ui.colIndx
      ,dataIndx: ui.dataIndx
      ,oldVal: ui.oldVal
      ,newVal: ui.newVal
      ,rowData: rowData
      ,keyCode:evt.keyCode
    });
    //window.console && console.log(json_arr);
    $('#Post_id').html(json_arr);
   
   
//if ((keyCode == 40 || keyCode == 38) && newVal != oldVal) {
    $.ajax({
    type: "POST",
    url:'PQGrid.asp?isl=Save',
    data:rowData,
    cache:false,
    statusCode: {404: function(){}},
    beforeSend: function(jqXHR, settings){
        alert('beforeSend\nstatus:'+jqXHR.status+'\n jqXHRstatusText:'+jqXHR.statusText);
        $('#overlay').show();
    },
    success: function(data,textStatus,jqXHR){
        alert('Success\nstatus:'+jqXHR.status+'\n jqXHRstatusText:'+jqXHR.statusText+'\n textStatus:'+textStatus);
        $('#Post_id').html(data).show();
    },
    error: function(jqXHR, textStatus, errorThrown){
        alert('Error\nstatus:'+jqXHR.status+'\n jqXHRstatusText:'+jqXHR.statusText+'\n textStatus:'+textStatus);
        $('<div></div>').html('Hata Kodu:'+jqXHR.status+'<br>'+jqXHR.statusText).dialog({position: ['center','top'],modal:true,zindex:9002,title:textStatus});
    },
    complete:function(jqXHR, textStatus) {
        alert('Complete\nstatus:'+jqXHR.status+'\n jqXHRstatusText:'+jqXHR.statusText+'\n textStatus:'+textStatus);
        $('#overlay').hide();
    }
    });
//}

    });

Html

Code: [Select]
<div style='float:left;width:40%;'>
<div id='Post_id'>Post Message</div>
<div id='Hata_id'>Error Message</div>
</div>

« Last Edit: November 24, 2013, 04:25:51 pm by omerix »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Cell Edit and Save,Return info
« Reply #1 on: November 25, 2013, 01:10:19 pm »
3) Send ajax request to check validity of data in validation callback. You have to make it synchronous ajax call.

http://paramquery.com/pro/api#option-column-validations

You can display custom message from Ajax call by assigning message string to ui.msg and return false if validation fails.

Example for usage of validation callback:

http://paramquery.com/pro/demos/editing_custom


2) Yes you can do that by modifying rowData. rowData is a reference to the data in a row.
rowData is available inside callbacks / events (e.g. cellSave, cellBeforeSave) and it can also be obtained by
API getRowData


1) evt.keyCode is not available inside cellSave. But that's a good point, I've added it in the upcoming version. As a workaround for v2.0.2
you have to fallback to cellEditKeyDown to detect evt.keyCode




Note: Please keep unrelated questions in different posts for better clarification.
« Last Edit: November 25, 2013, 01:12:08 pm by paramquery »