Articles in this section
Category / Section

How to check all the checkboxes in the content on clicking the header checkbox?

1 min read


Need to change the state of the content checkboxes on clicking the header checkbox.


Clicking the header checkbox automatically changes the state of the content checkboxes when the header template is used with template column in the ejGrid. You can set the change client side event to the header checkbox in the Grid create event and it is triggered when checked on the header checkbox. The state of the content checkboxes can be changed in the same header change function.

The actionComplete event is used to maintain its state while performing Grid actions such as paging.


   <div id="Grid">
<script type="text/javascript">
            dataSource: window.gridData,
            allowPaging: true,        
            create: "onCreate",
            actionComplete: "onActionComplete",
            columns: [
            { headerText: "Check", template: "<input type='checkbox' class='check' />", headerTemplateID: "#headerTemplate", textAlign: ej.TextAlign.Center, width: 100 },
                { field: "OrderID", headerText: "Order ID", width: 75, textAlign: ej.TextAlign.Right },
                { field: "CustomerID", headerText: "Customer ID", width: 80 },
                { field: "EmployeeID", headerText: "Employee ID", width: 75, textAlign: ej.TextAlign.Right }


        .Columns(col =>
            col.HeaderText("Check").Template("<input type='checkbox' class='check' />")             .HeaderTemplateID("#headerTemplate").TextAlign(TextAlign.Center).Width(100).Add();
            col.Field("OrderID").HeaderText("Order ID").TextAlign(TextAlign.Right).Width(100).Add();
            col.Field("CustomerID").HeaderText("Customer ID").Width(100).Add();
            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(100).Add();           
        .ClientSideEvents(eve => eve.ActionComplete("onActionComplete").Create("onCreate"))


<ej:Grid ID="FlatGrid" runat="server" AllowPaging="True">        
        <ClientSideEvents Create="onCreate" ActionComplete="onActionComplete" />
            <ej:Column HeaderText="Check" Template="<input type='checkbox' class='check' />" 
            HeaderTemplateID="#headerTemplate" TextAlign="Center" Width="100" />
            <ej:Column Field="OrderID" HeaderText="Order ID" TextAlign="Right" Width="100" />
            <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="100" />
            <ej:Column Field="EmployeeID" HeaderText="Employee ID" TextAlign="Right" Width="100" />                       

The following code example is common for all the three platforms.


  // Header Template.
    <script type="text/x-jsrender" id="headerTemplate">
    Checked <input type="checkbox" id="headerCheck" />
    <script type="text/javascript">
       // Grid creates function.
        function onCreate(args) {
                // Sets change event to the header checkbox.
                $("#headerCheck").ejCheckBox({ "change": "headerChecked" });
       // Header checkbox changes function.
        function headerChecked(args) {  
        // Grid actionComplete function.
        function onActionComplete(args) {
            if (args.requestType == "paging") // Maintain the checked state while paging
        function checkAll(flag) {
            $(".check").prop("checked", flag); // Check or uncheck all content check boxes            


The following screenshots display the header before being checked, after being checked and paging.

Figure 1: Before the change of header checkbox



Figure 2: After the change of header check box


Figure 3: After paging

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment