// This file locates: "Scripts/Lesson/C1FlexGrid/ColumnsStyling.js".
c1.documentReady(function () {
var cv = c1.getService("collectionView");
for (var i = 0; i < cv.items.length; i++) {
cv.items[i].Comment = i % 5 == 0 ? 'This item has a long comment so it will wrap in the cell.' : '';
}
// column properties
var theGrid = wijmo.Control.getControl('#theGrid');
theGrid.initialize({
autoGenerateColumns: false,
columns: [
{ binding: 'Id', header: 'ID', align: 'center', width: 50 },
{ binding: 'Country', header: 'Country', cssClass: 'cell-country' },
{ binding: 'Product', header: 'Product', cssClass: 'cell-product' },
{ binding: 'Comment', header: 'Comment', wordWrap: true, width: 200 },
{ binding: 'Sales', header: 'Sales', format: 'c0', align: 'center' },
{ binding: 'Expenses', header: 'Expenses', format: 'c0', align: 'center' },
],
});
// call autosizerows to show word-wrapping
theGrid.autoSizeRows();
// formatItem event
var theGridFormatItem = wijmo.Control.getControl('#theGridFormatItem');
theGridFormatItem.initialize({
autoGenerateColumns: false,
columns: [
{ binding: 'Country', header: 'Country' },
{ binding: 'Product', header: 'Product' },
{ binding: 'Sales', header: 'Sales', format: 'c0' },
{ binding: 'Expenses', header: 'Expenses', format: 'c0' },
],
formatItem: function (s, e) {
if (e.panel == s.cells) {
var value = e.panel.getCellData(e.row, e.col);
wijmo.toggleClass(e.cell, 'high-value', wijmo.isNumber(value) && value > 60000);
wijmo.toggleClass(e.cell, 'low-value', wijmo.isNumber(value) && value < 20000);
}
}
});
});
// This file locates: "Content/css/Lesson/C1FlexGrid/ColumnsStyling.css".
.wj-flexgrid {
max-height: 250px;
}
.cell-country {
font-weight: bold
}
.cell-country:not(.wj-state-selected):not(.wj-state-multi-selected) {
background-color: #bbff00 !important;
}
.cell-product {
font-weight: bold;
}
.cell-product:not(.wj-state-selected):not(.wj-state-multi-selected) {
background-color: #ffbb00 !important;
}
.high-value {
font-weight: bold;
color: green;
}
.low-value {
font-style: italic;
color: red;
}
using System.Web.Mvc;
namespace LearnMvcClient.Controllers
{
public partial class C1FlexGridController : Controller
{
// GET: ColumnsStyling
public ActionResult ColumnsStyling()
{
return View(Models.FlexGridData.GetSales(200));
}
}
}
@model IEnumerable<FlexGridData.Sale>
<h1>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Title)
</h1>
<p>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Text1)
</p>
<ul>
<li>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Text2)
</li>
<li>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Text3)
</li>
<li>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Text4)
</li>
</ul>
<p>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Text5)
</p>
<p>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Text6)
</p>
@Html.C1().CollectionViewService().Id("collectionView").Bind(Model)
@(Html.C1().FlexGrid().Id("theGrid")
.ItemsSourceId("collectionView")
.ShowAlternatingRows(false)
)
<h3>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Title1)
</h3>
<p>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Text7)
</p>
<p>
@Html.Raw(Resources.C1FlexGrid.ColumnsStyling_Text8)
</p>
@(Html.C1().FlexGrid().Id("theGridFormatItem")
.ItemsSourceId("collectionView")
.ShowAlternatingRows(false)
)