How to dynamically change data source (js) for datatable with select ext. and clear selection?

How to dynamically change data source (js) for datatable with select ext. and clear selection?

rocheroche Posts: 4Questions: 1Answers: 0
edited September 2015 in Free community support

I need help with datatable. I'm using datatable 1.10.9 with Select extension.

I'm trying to load a lookup table in a modal for a page. The lookup table may load different data source and should be selectable (single selection).

On the function that show up the modal, I create a dummySet with javascript to populate the table, then I initialized datatable with this setting:

var $dt = $("#lookup-modal #lookup-table").DataTable({
                "destroy": true,
                "data": dummySet,
                "searching": false,
                "ordering":  true,
                "select": true,
                "lengthChange": false,
                "paging": false,
                "info": false,
                "autoWidth": false,
                "aoColumnDefs": [{
                    "bSortable" : false,
                    "aTargets" : [ "dt-nosort" ]
                }]
            });

When modal loads up, table is fine, it changed the source okay and I can select any row just fine.

Problem appears when I output the selected row data with:

console.log($dt.row( { selected: true } ).data());

First time the modal loads up, it shows the data for the row I selected once. (CORRECT)
But If I close the modal then load it up again, it shows the data for the selected row, as many as the times the modal loads up. So if the modal loads up 4 times, my log will show the selected row data 4 times (when it should be once).

Deselecting the rows doesn't seem to help. Clearing the table does clear the previous selected row to undefined, but it still return the data more than once.

Can anyone give me a solution to this, or explanation as to why this is happening?

Thanks.

This discussion has been closed.