Simple Inline editing detect value and do action

Simple Inline editing detect value and do action

bilusesbiluses Posts: 26Questions: 10Answers: 0
edited July 2017 in Free community support

Hi there!

i have already implemented simple inline editor like that:

$('#example').on( 'click', 'tbody td:not(.child), tbody span.dtr-data', function (e) {
// Ignore the Responsive control and checkbox columns
if ( $(this).hasClass('select-checkbox') ) {
return;
}
editor.inline( this );
} ),

What i need is:
-Detect when the cell 'data.incomes.status' is updated with the value "Validated", make an ajax call to update other database value.

How can i check if the cell 'data.incomes.status' is updated using the inline editor? with only that i can do the rest. Is there a "updated function" to call or something like that?

thanks for the help

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    postEdit sounds like what you want. That will be triggered when a row's data is updated via Editor.

    Allan

  • bilusesbiluses Posts: 26Questions: 10Answers: 0

    @allan Do you have any example of use?
    i have this:
    editor.on('submitSuccess', function(e, json, data)
    { ....

    Should i use?:
    editor.on('postEdit', function(e, json, data)
    { ....

  • bilusesbiluses Posts: 26Questions: 10Answers: 0

    other question, why when i update, it fired 2 times the ajax call? it's like it is recharging data 2 times, or making 2 times the submit. this is the code.

    editor.on('postEdit', function(e, json, data)
    {
    var modifier = editor.modifier();
    var currentRow = table.row(modifier).node();

            console.log(loaded + ' once');
            if (data.incomes.status == 2 || data.incomes.status == 3 || data.incomes.status == 4 || data.incomes.status == 5 || data.incomes.status == 6) 
            {
                loaded ++;
                    //get the object value of the row ID
                    var myobj = table.row( editor.modifier() ).data();
                    var keysArray = Object.keys(myobj);
                    var valuesArray = Object.keys(myobj).map(function(k) {
                       return String(myobj[k]);
                    });
                    var mydata = valuesArray[keysArray.indexOf("DT_RowId")]; 
                    var resId = mydata.substring(4);
                    // var resultado = $('td', currentRow).eq(11).text();
                    console.log(loaded +' second');
                    if(loaded >= 2) return;
    
                    $.ajax({
                        type: "POST",
                        url: "php/update_docname.php",
                        data: {
                                advid: resId
                            },
                        success: function(data) {
                        }
                    });
            } 
        });
    
  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    Should i use?: ...

    Looks right to me :)

    other question, why when i update, it fired 2 times the ajax call?

    I'd need a link to a test case showing the issue to understand why that is happening. Perhaps you have server-side processing enabled?

    Allan

  • bilusesbiluses Posts: 26Questions: 10Answers: 0

    @allan Solved, problem was i was firing the " editor.on('postEdit', function(e, json, data) " inside the "$('#example').on( 'click', 'tbody td:not(.child), tbody span.dtr-data', function (e) {" so any time i click for edit, it fires the function.

    One more last question.
    in the function "editor.on('postEdit', function(e, json, data)" is it possible to know who is the value that make the postEdit?

    For example. I have a table with values: Name, Surname, Mobile, Money.
    i want to know if the postedit happens on the Name, or Mobile, to create a condition for example:
    if postEdit happens, if happens on data.Money, if data.money > 100 then...
    So is it possible to know wich data is making the postedit?

    THANKS!!!!

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin
    Answer ✓

    Which value being edited is triggering the postEdit event? Yes, the original data will be in the data object, and if you have it submitting only the changed values, then only the changed values will be in that object.

    Allan

  • bilusesbiluses Posts: 26Questions: 10Answers: 0

    @allan thanks Allan, you're awesome! it's working perfectly.

This discussion has been closed.