admin管理员组文章数量:1435859
<script type="text/template" id="date-cell">
<%= date.dateBegin %> até <%= date.dateEnd %>
<br>
<%= date.timeBegin %> até <%= date.timeEnd %>
</script>
<script type="text/template" id="status-cell">
<% if (order.enable) { %>
<% _.each(order.contacts, function(contact) { %>
<span class="contact-type"><%= contact.value %></span>
<% }); %>
<% } else { %>
<% if (order.expired) { %>
<span class="label label-expired">Expirado</span>
<% } else { %>
<span class="label label-closed">Fechado</span>
<% } %>
<% } %>
</script>
<script type="text/javascript">
var onRefreshGrid;
$(function() {
var Order,
OrderCollection,
orders,
grid;
Order = Backbone.Model.extend({});
OrderCollection = Backbone.Collection.extend({
modal: Order,
url: 'http://localhost:2000/orders.php'
});
orders = new OrderCollection();
var columns = [{
name : "hash",
label: "Cod. Pedido",
cell : 'string',
editable: false
},
{
name : "user",
label: "Nome",
cell: "string",
editable: false
},
{
name : "order",
label: "Status",
cell : Backgrid.StringCell.extend({
template: _.template($('#status-cell').html()),
render: function () {
this.$el.html(this.template(this.model.attributes));
return this;
}
}),
editable: false
},
{
name : "date",
label: "Data",
cell: Backgrid.StringCell.extend({
template: _.template(
$('#date-cell').html()
),
render: function() {
this.$el.html(this.template(this.model.attributes));
return this;
}
}),
editable: false
}];
// Initialize a new Grid instance
grid = new Backgrid.Grid({
columns: columns,
collection: orders
});
// Render the grid and attach the root to your HTML document
$('#datagrid').append(grid.render().el);
onRefreshGrid = function () {
orders.fetch({});
};
// auto execute
onRefreshGrid();
});
</script>
I need to add a background-color to each row (tr) according to a condition, was looking at the documentation met "Backgrid.Row.extend" what you can do, just that I need to create a base template .. that would replicate in each row (tr), just that I also have some columns costumizo as the code shows. My question is .. You can add an event to listen to each line and I can only change its attributes without disrupting the structure (html)?
<script type="text/template" id="date-cell">
<%= date.dateBegin %> até <%= date.dateEnd %>
<br>
<%= date.timeBegin %> até <%= date.timeEnd %>
</script>
<script type="text/template" id="status-cell">
<% if (order.enable) { %>
<% _.each(order.contacts, function(contact) { %>
<span class="contact-type"><%= contact.value %></span>
<% }); %>
<% } else { %>
<% if (order.expired) { %>
<span class="label label-expired">Expirado</span>
<% } else { %>
<span class="label label-closed">Fechado</span>
<% } %>
<% } %>
</script>
<script type="text/javascript">
var onRefreshGrid;
$(function() {
var Order,
OrderCollection,
orders,
grid;
Order = Backbone.Model.extend({});
OrderCollection = Backbone.Collection.extend({
modal: Order,
url: 'http://localhost:2000/orders.php'
});
orders = new OrderCollection();
var columns = [{
name : "hash",
label: "Cod. Pedido",
cell : 'string',
editable: false
},
{
name : "user",
label: "Nome",
cell: "string",
editable: false
},
{
name : "order",
label: "Status",
cell : Backgrid.StringCell.extend({
template: _.template($('#status-cell').html()),
render: function () {
this.$el.html(this.template(this.model.attributes));
return this;
}
}),
editable: false
},
{
name : "date",
label: "Data",
cell: Backgrid.StringCell.extend({
template: _.template(
$('#date-cell').html()
),
render: function() {
this.$el.html(this.template(this.model.attributes));
return this;
}
}),
editable: false
}];
// Initialize a new Grid instance
grid = new Backgrid.Grid({
columns: columns,
collection: orders
});
// Render the grid and attach the root to your HTML document
$('#datagrid').append(grid.render().el);
onRefreshGrid = function () {
orders.fetch({});
};
// auto execute
onRefreshGrid();
});
</script>
I need to add a background-color to each row (tr) according to a condition, was looking at the documentation met "Backgrid.Row.extend" what you can do, just that I need to create a base template .. that would replicate in each row (tr), just that I also have some columns costumizo as the code shows. My question is .. You can add an event to listen to each line and I can only change its attributes without disrupting the structure (html)?
Share Improve this question edited Jan 22, 2014 at 18:53 Hugo Henrique asked Jan 22, 2014 at 18:48 Hugo HenriqueHugo Henrique 311 silver badge2 bronze badges 1- Anything you want to do. To fix classes in Backgrid currently is an AWFUL HACK: github./wyuenho/backgrid/issues/465 – cliffbarnes Commented Jan 12, 2015 at 10:40
1 Answer
Reset to default 4Every Row or Cell instance will have access to the entire model. You can access them from within your render
method and add your CSS classes there. Something like this will do:
var MyRow = Backgrid.Row.extend({
render: function () {
MyRow.__super__.render.apply(this, arguments);
if (this.model.get("someAttribute")) {
this.el.classList.add("aClass");
}
return this;
}
});
A row is a row, they are all the same. No need to use a template.
本文标签: javascripthow to customize backgrid rowStack Overflow
版权声明:本文标题:javascript - how to customize backgrid row - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745672756a2669671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论