I have an overview table that displays my model. I need to be able to select multiple records from that table to perform an action on that collection of selected items. So I’ve added a checkbox on each row.
Do I need to bind that checkbox onto a model property (introducing an isSelected property on my model), or can it be done on the controller level ?
I know the TodoMvc app does the binding to the model that, but there the isCompleted is really part of the core “todo” model.
In my case, it’s a pure UI thing (toggling a selection).
I’ve been playing around with this and I can get it to work but only if I bind it to my model.
The overview table :
{{#each item in controller itemController="location"}}
<tr>
<td>{{view Ember.Checkbox checkedBinding="selected"}}</td>
<td>{{item.prop1}}</td>
<td>{{item.prop2}}</td>
</tr>
{{/each}}
counter = {{editCounter}}
<button {{action 'handleSelectedRecords'}}>Handle selected</button>
The selected binding is done on the location controller (ObjectController) and not directly on the model. The editCounter and handleSelectedRecords are defined on the ArrayController that displays the table
The selected property on the array controller looks like this:
selected: function(key,value) {
//this.get("content").set("selected",value); // if I don't do this ten the editCounter is never triggered.
return value;
}.property()
Notice how the rest of the solution fails if I don’t update the selected property on the model.
The counter is implemented like this:
editCounter: function () {
return this.filterProperty('selected', true).get('length'); // again this works on the model property I guess
}.property('@each.selected')
And the handleSelectedRecords like this
handleSelectedRecords: function() { arr = this.filterProperty(‘selected’, true); for (i=0 ; i<arr.length ; i++) { console.log("found selected " + arr[i]) } }
Is there a way to do this without putting the “selected” property on them model ? From a design point of view, the selected property should be part of the controller, but then how do I get the editCounter and the handleSelectedRecords to work ?