Skip to content

Create a header template, add a check box to the template, and implement the Select All functionality in batch edit mode.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-select-all-checkbox-in-batch-edit-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - Implement the Select All check box for a templated column in batch edit mode

This example demonstrates how to create a header template, add a check box to the template, and implement the Select All functionality in batch edit mode.

SelectAllCheckBox

Overview

Follow the steps below to implement the Select All functionality in a column's header in batch edit mode:

  1. Specify a column's HeaderTemplate property and add a check box editor to the template.

    <dx:GridViewDataCheckColumn FieldName="Discontinued" VisibleIndex="6">
        <!-- ... -->
        <HeaderTemplate>
            <dx:ASPxCheckBox ID="HeaderCheckBox" ClientIDMode="Static" runat="server"
                ClientInstanceName="HeaderCheckBox" ... >
                <ClientSideEvents CheckedChanged="OnHeaderCheckBoxCheckedChanged" Init="OnInitHeader" />
            </dx:ASPxCheckBox>
        </HeaderTemplate>
        <Settings AllowSort="False" />
    </dx:GridViewDataCheckColumn>
  2. Handle the editor's client-side CheckedChanged event. In the handler, call the grid's SetCellValue method to assign a value to the specified cell based on the check box state.

    function OnHeaderCheckBoxCheckedChanged(s, e) {
        var visibleIndices = Grid.batchEditApi.GetRowVisibleIndices();
        var totalRowsCountOnPage = visibleIndices.length;
        for (var i = 0; i < totalRowsCountOnPage ; i++) {
            Grid.batchEditApi.SetCellValue(visibleIndices[i], "Discontinued", s.GetChecked())
        }
    }
  3. Handle the grid's client-side BatchEditEndEditing, BatchEditRowDeleting, and BatchEditRowInserting events. In the handlers, call the CheckSelectedCellsOnPage function. In this function, compare the number of selected rows and the total number of visible rows. Based on a result, specify the state of the checkbox editor.

    function CheckSelectedCellsOnPage(checkType) {
        var currentlySelectedRowsCount = 0;
        var visibleIndices = Grid.batchEditApi.GetRowVisibleIndices();
        var totalRowsCountOnPage = visibleIndices.length;
        for (var i = 0; i < totalRowsCountOnPage ; i++) {
            if (Grid.batchEditApi.GetCellValue(visibleIndices[i], "Discontinued"))
                currentlySelectedRowsCount++;
        }
        if (checkType == "insertCheck")
            totalRowsCountOnPage++;
        else if (checkType == "deleteCheck") {
            totalRowsCountOnPage--;
            if (DeletedValue)
                currentlySelectedRowsCount--;
        }
        if (currentlySelectedRowsCount <= 0)
            HeaderCheckBox.SetCheckState("Unchecked");
        else if (currentlySelectedRowsCount >= totalRowsCountOnPage)
            HeaderCheckBox.SetCheckState("Checked");
        else
            HeaderCheckBox.SetCheckState("Indeterminate");
    }

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Create a header template, add a check box to the template, and implement the Select All functionality in batch edit mode.

Topics

Resources

License

Stars

Watchers

Forks