Row.add option

Row.add option

dkwebdkweb Posts: 2Questions: 1Answers: 0

i use the following:
.row
.add([
person.id,
person.name,
person.control
])
.draw()

Is it possible to pass an object or array directly using row.add.draw option?
i.e.
.row
.add([person])
.draw()
i prepare data in my model and object params equal number of columns...
Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,356Questions: 1Answers: 10,447 Site admin
    Answer ✓

    Sure - just do row.add( person ) if person is either an object or array that matches the data format that DataTables has been told to use (e.g. through the use of columns.data).

    Allan

  • dkwebdkweb Posts: 2Questions: 1Answers: 0

    Dear Allan! First of all thanks for a great plugin.
    Sure, i tried to do so.. but may be the problem is that i do not define columns...

    var table = $('#tab1').DataTable(

        {
            "order": [
                [1, "asc"]
            ],
            "language": {
                "url": "vendor/datatables/Russian.json"
            },
            "columnDefs": [{
                "targets": [3],
                "visible": false
            }, {
                "width": "40%",
                "targets": 5
            }]
        }
    
    
    );
    

    This is the only what i have

  • allanallan Posts: 63,356Questions: 1Answers: 10,447 Site admin

    If that is the case then DataTables is expecting arrays for the data in each row. You need to give it the same format that it has been "told" to expect in row.add().

    You can use columns.data to read data into an object structure as this example shows which you might find useful.

    Allan

This discussion has been closed.