Vertical Alignment

In most of the cases, the vertical alignment of content within FlexGrid cells doesn't matter, since cells contain only a single row of content. However, in some situations you may want to control the vertical alignment of some or all cells. For example, when showing wrapping text or merging cells vertically.

To control the vertical alignment of FlexGrid cells, you should use the formatItem event and modify the cell's HTML to achieve the result you want.

For example, the grid below has cells that are vertically aligned using a CSS transform:

Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
0
US
Phones
145,248
81,732.54
38,401.13
1
Germany
Computers
111,632
20,603.32
27,944.24
2
UK
Cameras
181,205
44,217.79
48,877.49
3
Japan
Stereos
54,740
29,190.63
23,365.74
4
Italy
Phones
126,531
46,951.19
49,107.56
5
Greece
Computers
6,073
86,237.02
49,767.35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// This file locates: "Scripts/Lesson/C1FlexGrid/RowsStylingVerticalAlignment.js".
c1.documentReady(function () {
    var theGrid = wijmo.Control.getControl('#theGrid');
 
    // make rows taller to show the vertical alignment
    theGrid.rows.defaultSize = 45;
    theGrid.columnHeaders.rows.defaultSize = 65;
    theGrid.allowResizing = 'Both';
    theGrid.deferResizing = true;
   
    // use formatItem event to apply transform
    theGrid.formatItem.addHandler(function (s, e) {
        if (!e.cell.querySelector('input')) {
            e.cell.innerHTML = '<div class="v-center">' +
            e.cell.innerHTML +
          '</div>';
        }
    });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// This file locates: "Content/css/Lesson/C1FlexGrid/RowsStylingVerticalAlignment.css".
.wj-flexgrid {
  max-height: 250px;
}
.wj-cell .v-center {
  position: relative;
  top: 50%;
    transform: translateY(-50%);
  white-space: pre-wrap;
}
.wj-cell input[type=checkbox] {
  position: relative;
  margin: 0;
  top: 50%;
    transform: translateY(-50%);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1FlexGridController : Controller
    {
        // GET: RowsStylingVerticalAlignment
        public ActionResult RowsStylingVerticalAlignment()
        {
            return View(Models.FlexGridData.GetSales());
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@model IEnumerable<FlexGridData.Sale>
 
<h1>
    @Html.Raw(Resources.C1FlexGrid.RowsStylingVerticalAlignment_Title)
</h1>
<p>
    @Html.Raw(Resources.C1FlexGrid.RowsStylingVerticalAlignment_Text1)
</p>
<p>
    @Html.Raw(Resources.C1FlexGrid.RowsStylingVerticalAlignment_Text2)
</p>
<p>
    @Html.Raw(Resources.C1FlexGrid.RowsStylingVerticalAlignment_Text3)
</p>
@Html.C1().FlexGrid().Id("theGrid").Bind(Model)