Looking for example to redraw edited row after submission

Looking for example to redraw edited row after submission

crcucbcrcucb Posts: 59Questions: 17Answers: 0

I have a datatable whose source is MS Sql table via PHP. If a record has a column 'Inactive' = 1, then I apply a class in createdRow:

createdRow: function (row, data, dataIndex) {
if ( data.view_Addresses.Ignore == 1) {
$(row).addClass('strikethrough-row');
console.log('ignore dataIndex',dataIndex);
}
}

This works however after I edit, if the actions of the edit was setting Ignore it doesn't refresh the row (apply the strikethrough class). I need to manually refresh the datatable.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,155Questions: 92Answers: 433
    edited July 21

    Have you tried

    $(row).addClass('strikethrough-row').draw(false);
    

    Please use Markdown to format your code!

  • allanallan Posts: 64,798Questions: 1Answers: 10,728 Site admin
    Answer ✓

    I can add a little more information here. createdRow will trigger once and once only (when the row is created), so it isn't all that useful for data which might update (either via Editor or by something else).

    Instead, in this case use rowCallback - this is triggered whenever the row is drawn in the table. As a result it can be called when there is no update (i.e. just searching or paging the table), but it will be called on a draw from an update.

    So:

    rowCallback: function (row, data) {
        $(row).toggleClass('strikethrough-row', data.view_Addresses.Ignore == 1);
    }
    

    should do the job. Note that I've used toggleClass since your edit could also remove the strike-through condition (I presume).

    Allan

  • crcucbcrcucb Posts: 59Questions: 17Answers: 0
    edited July 21

    Thank you for the extra tip. I modified the rowCallBack to test for needing to change both ways:

     rowCallback: function (row, data) {
                 if (( data.view_Addresses.Ignore  == 1) &&   ($(row).hasClass('strikethrough-row') === false)) { 
    $(row).toggleClass('strikethrough-row', data.view_Addresses.Ignore == 1);
                         
                  }
                if (( data.view_Addresses.Ignore  == 0) &&   ($(row).hasClass('strikethrough-row'))) {
                                $(row).toggleClass('strikethrough-row', data.view_Addresses.Ignore == 1);
                         
                  }
           
         }
        },
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Sign In or Register to comment.