Controls and Elements

Every MVC control is associated with an HTML element that hosts it on the page.

To get a reference to the element hosting the control, use the hostElement property (available in every C1 MVC control). Use the static method wijmo.Control.getControl(element) to get a reference to the control being hosted by an element.

In applications having tab controls or dynamic views, the control layout often becomes invalid if the size or visibility of the host element is changed and the control is not notified about the same.

However, in case of MVC controls, layout of all the controls is updated according to the size of their host elements. MVC controls provide wijmo.Control.invalidateAll method to notify the controls about change in their host element, so that the controls update their layout accordingly.

For example, use the buttons below to observe resizing in the grid in two cases; without using invalidateAll method (WRONG way) and the case using invalidateAll method (RIGHT way):

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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// This file locates: "Scripts/Lesson/C1Mvc/ControlsElements.js".
c1.documentReady(function () {
    var grid = wijmo.Control.getControl('#theGrid');
 
    // toggle grid's font
    document.getElementById('toggleFont').addEventListener('click', function () {
 
        // get control being hosted by element #theGrid
        var ctl = wijmo.Control.getControl('#theGrid');
 
        // get host element from 'grid' control
        var host = ctl.hostElement;
 
        // toggle font weight
        var style = host.style;
        style.fontWeight = style.fontWeight ? '' : 'bold';
    });
 
    // resize the grid the WRONG way
    document.getElementById('resizeBad').addEventListener('click', function () {
        var style = grid.hostElement.style;
        style.height = style.height ? '' : '100px';
    });
 
    // resize the grid the RIGHT way
    document.getElementById('resizeGood').addEventListener('click', function () {
        var style = grid.hostElement.style;
        style.height = style.height ? '' : '100px';
        grid.invalidate(); // update control layout after resizing the element
 
        // or (if you have many controls)
        //wijmo.Control.invalidateAll();
    });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1MvcController : Controller
    {
        // GET: ControlsElements
        public ActionResult ControlsElements()
        {
            return View(Models.FlexGridData.GetSales());
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@model IEnumerable<FlexGridData.Sale>
 
<h1>
    @Html.Raw(Resources.C1Mvc.ControlsElements_Title)
</h1>
<p>
    @Html.Raw(Resources.C1Mvc.ControlsElements_Text1)
</p>
 
<p>
    @Html.Raw(Resources.C1Mvc.ControlsElements_Text2)
</p>
 
 
<p>@Html.Raw(Resources.C1Mvc.ControlsElements_Text3)</p>
 
<p>
    @Html.Raw(Resources.C1Mvc.ControlsElements_Text4)
</p>
 
<p>
    @Html.Raw(Resources.C1Mvc.ControlsElements_Text5)
</p>
 
<button id="toggleFont" class="btn btn-primary">@Html.Raw(Resources.C1Mvc.ControlsElements_Text6)</button>
<button id="resizeBad" class="btn btn-danger">@Html.Raw(Resources.C1Mvc.ControlsElements_Text7)</button>
<button id="resizeGood" class="btn btn-success">@Html.Raw(Resources.C1Mvc.ControlsElements_Text8)</button>
@Html.C1().FlexGrid().Id("theGrid").Bind(Model).ShowMarquee(true).ShowSelectedHeaders(C1.Web.Mvc.Grid.HeadersVisibility.All).ShowAlternatingRows(false)