I want to set one field value in presubmit, but the value is always not change in datatable

I want to set one field value in presubmit, but the value is always not change in datatable

BennyxuBennyxu Posts: 22Questions: 3Answers: 0

in my case, there is one calculation field (calculate the total amount), I put this calculation in presubmit even, I can see it has been change in pop-up edit window, when I click confirm button, all other fields value are correct, but the calculation field value is nothing, how can I do, it is urgent to me, thanks in advance.\

Benny

Replies

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    Hi Benny,

    Can you show use the code you are using please? Or ideally, link me to the page so I can take a look and debug it live.

    Thanks,
    Allan

  • BennyxuBennyxu Posts: 22Questions: 3Answers: 0
    edited June 2014

    just simplify the code, it like below , pls help check, thanks a lot.

      function validation(e,o){
            var me=this;
            /*
            for(var i in o.data){
                o.data[i]=M.str.trim(o.data[i]);
            }*/
            //set form field value
            $("currency_local").value =200;
            return true;
        }
        
        editor.on( 'preSubmit',validation);  //execute presubmit
    
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    I'm not sure I fully understand the code above. It looks like you are using jQuery to get a <currency_local> element and setting its value to be 200. Am I right in assuming that you want to set the currency_local property that is to be sent to the server? If so, use:

    function validation(e,o){
          o.data.currency_local = 200;
    }
       
     editor.on( 'preSubmit',validation);  //execute presubmit
    

    Allan

  • BennyxuBennyxu Posts: 22Questions: 3Answers: 0

    Hi, Allen

    Thanks a lot for your quick response, actually I am also set the value to o.data, just like your above clause, but the field currency_local is alway show 0 in main form, I have capture the HTML elements, only manual key in value in elements, the value set in presubmit does not take effect, do you have any simple sample for me reference,

  • BennyxuBennyxu Posts: 22Questions: 3Answers: 0

    Hi, Allen

    You are right, it is my fault, appreciated!!!!

  • BennyxuBennyxu Posts: 22Questions: 3Answers: 0

    sorry, typo, allan, thanks^^

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    Good to hear that helped :-)

    Allan

  • BennyxuBennyxu Posts: 22Questions: 3Answers: 0

    Hi, Allan & all

    I still have one question, I found the object (o) has been update but the field value is not updated in datatable, seems any data change in presubmit action, datatable will not be refreshed even the backend object o is updated, do you have any method to resolve it or reload the datatable again.

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    Are you returning the data for the row in the row parameter from the server? The client / server comms protocol for Editor is documented in the manual with information about the row parameter.

    Allan

  • BennyxuBennyxu Posts: 22Questions: 3Answers: 0
    edited June 2014

    Dear allan
    We are not using client/server approach(ajax), the method is to overwrite local storage

    part of code as below,

        var getData=function(){
            var store=JSON.parse( sessionStorage.getItem(options.db) );
            for(var i in store){    //remove DT_RowId
                var e=store[i];
                delete e.DT_RowId;
            }
            return(store);
        }
    
    
    DT.view.current=$('#DataTablesView').dataTable( {
            language:DT.options.language,
            "aoColumnDefs": options.aoColumnDefs,
            "data": options.data,
            "columns": options.columns,
            //"sDom": "lfrtip",
            //"bInfo": false,
            fnRowCallback: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                // Row click
                /*
                $(nRow).on('dblclick', function() {
                    var _id=aData[0];
                    wfdoc.open(_id);
                  //console.log('Row Clicked. Look I have access to all params, thank You closures.', this, aData, iDisplayIndex, iDisplayIndexFull);
                });
                */
                if(options.dblclick){
                     $(nRow).on('dblclick', function(){
                         options.dblclick(nRow, aData, iDisplayIndex, iDisplayIndexFull);
                     });
                }
                if(options.click){
                     $(nRow).on('click', function(){
                         options.click(nRow, aData, iDisplayIndex, iDisplayIndexFull);
                     });
                }
                // Cell click
                /*
                $('td', nRow).on('click', function() {
                  console.log('Col Clicked.', this, aData, iDisplayIndex, iDisplayIndexFull);
                });
                */
              }
        } );   
    
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    That's for the code. I don't see where it would be returning the row parameter, as described in the Editor manual? It looks like it is just returning the entire data structure.

    Allan

  • BennyxuBennyxu Posts: 22Questions: 3Answers: 0

    yes,you are correct,
    anyway I am using another approach to update the row data, thanks ^^

                    iCurrentRecords_2 = fnGetSelected(dte_2.table);
                    if (iCurrentRecords_2==0)
                    {
                      //get current row
                      iCurrentRecords_2 = getTotalRecords(dte_2);
                    }
                    var num_updcolumn = 7;
                    dte_2.table.fnUpdate(DT.form.fieldGet('currency_local'),iCurrentRecords_2-1,num_updcolumn); 
                    //end update
    
This discussion has been closed.