How to get record if exists then change value for new

How to get record if exists then change value for new

przeqpicielprzeqpiciel Posts: 2Questions: 1Answers: 0

My code is very simple

var table = $('#summary').DataTable();
            table.row.add(['111', 'wert56456']).draw();
            table.row.add(['222', 'wert56456']).draw();
            table.row.add(['444', 'wert56456']).draw();
            table.row.add(['333', 'wert56456']).draw();
            result = table.search('2348234');
            console.log(result.row().data());

How to get specific row, eg. containing in first column 333 and change column to other value ?

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited April 2022

    Use the row() selector method with a suitable row-selector. For example:

    table.row((idx, data) => data[0] === '333');
    

    Then use row().data() or cell().data() to update the data as needed.

    Allan

  • przeqpicielprzeqpiciel Posts: 2Questions: 1Answers: 0

    What an answer !!

    I did it with filter()

    table.column(0)
                    .data()
                    .filter(function(value, index){
                        if (value === CLI)
                        {
                            data = table.row(index).data();
                            data[1]++;
                            table.row(index).data(data).draw();
                        }
                        return value === CLI ? 'alfabet' : false;
                    });
    
Sign In or Register to comment.