Rafalsonn
Rafalsonn

Reputation: 440

Ember.js Multiple Selection in a Table

I'm newbie in Ember.js framework, and I have a problem, I need a multiple selection of rows in a table.
I'm using jQuery Datatables, with Ember-Data, and I need to have an ID of the selected rows, something like push to the array and I have no clue how to do this.

Upvotes: 0

Views: 201

Answers (1)

cee_four
cee_four

Reputation: 44

For multiple selection, make sure you initialize the table with the select option set to "multi":

this.$("#myDT").DataTable({
    select: "multi"
});

When you want to get the list of all the rows selected, use a jQuery selector to get all the rows that have the selected class and get their data. In this example, the ID is the first column in the data, hence the [0]

var selectedRows = Ember.$('#myDT tbody tr.selected');
var selectedIDs = [];
Ember.$.each(selectedRows, function (i, element) {
    selectedIDs.push(table.row(element).data()[0]);
});

You can read more about DataTables API (for things like getting row data using the row.data() method here: https://datatables.net/reference/api/

Upvotes: 1

Related Questions