Datatable row.Add() not working.

Datatable row.Add() not working.

maulikDavemaulikDave Posts: 23Questions: 8Answers: 0

Hi, this is a Quite tricky one, I am using DataTable with Dropdown in every row
Now I want to add a new row on a click event

The DAtatable looks as below...

function BindTable() {
        if ($.fn.DataTable.isDataTable("#tblPool")) {
            $('#blPool').DataTable().destroy();
        }

         table = $("#tblPool").DataTable({
            "destroy": true,
            "serverSide": true,
            "bRetrieve": true,
            "searching": false,
            "order": [1, "asc"],
            "async": true,
            "pagingType": "simple",
            "dom": '',
            "language": {
                "paginate": {
                    "next": '<span><img src="images/next.svg" id="next" alt="next-arrow" /></span>',
                    "previous": '<span><img src="images/previous.svg" id="prev" alt="prev-arrow" /></span>'
                }
            },
            "ajax": {
                "url": "/Pool/GetPoolDetail",
                "type": "Post",
                "datatype": "json",
                "dataSrc": "PoolDetail",
                "data": function (d) {
                    return getSearchValues(d)
                }
            },
            "columns": [
                {
                    "title": "Id", "data": "id", "visible": false, 
                },
                {
                    "title": "resi", "data": "resiId", "visible": true,
                    "render": function (data, type, row) {
                        return resDetails(row.resiId, row.id);
                    }
                },
                {
                    "title": "Unit", "data": "unitId", "visible": true,
                    "render": function (data, type, row) {
                        return unitDetails(row.unitId, row.id)
                    }
                },
                {
                    "title": "Emp Name", "data": "empId", "visible": true,
                    "render": function (data, type, row) {
                        return empDetails(row.empId, row.id)
                    }
                },
              
                Other Columns.......

Each render Functions returns a select List and bind it in row

Now I am trying to add a new row on a button click event

Here is the code...

$('#addRow').on('click', function () {
        var resident = resiDetails(0, 0);
        var unit = unitDetails(0, 0);
        var employee = empDetails(0, 0);

        Other Variables

Now in each above variable, I am getting an HTML string like '<select><option val =1>test</option>></select>'
and at the end I creating a object and put all values in it

  var row = {
            "id": 0,
            "resiId": resident,
            "unitId": unit,
            "empId": employee,
            other Data....
}

 table.rows.add(row).draw(true);

But I am not able to add a new row, No error is showing but New row is also not added...
Please help me with this

Answers

This discussion has been closed.