New StaticDataSource will construct datasource for fuelux grid. The formatter will set the property to generate editable button in datagrid cell. The code is as follows:
app.PlayersView = Backbone.View.extend({
template: _.template( $("#players-template").html() ),
events: {
"click #addUser" : "addUser",
},
initialize: function () {
if(this.collection){
this.collection.fetch();
}
this.listenTo(this.collection, 'all', this.render);
},
render: function () {
this.$el.html( this.template );
var dataSource = new StaticDataSource({
columns: [
{
property: 'username',
label: 'Username',
sortable: true
},
{
property: 'group',
label: 'Groups',
sortable: true
},
{
property: 'edit',
label: 'Edit',
sortable: true
}
],
formatter: function (items) {
$.each(items, function (index, item) {
item.edit = '<div class="btn-group"><a id="editGroup" class="btn">Edit</a></div>';
});
},
data: this.collection.toJSON(),
delay: 250
});
$('#MyGrid').datagrid({
dataSource: dataSource,
stretchHeight: true
});
});
The app.Playerview object is created somewhere in bakcbone router as follows:
new app.PlayersView({
collection : new app.UsersCollection
}));
Here, column are username, groups and edit. The edit column for each row contains edit button. When I click the edit button in any row, I want to pass the particular row modal or row data to any other backbone view. How can we do that?
Actualy I will open the dialog that will allow to edit that particular row. I want modal to be pre-populated by that row value.
Thanks in advance