Mithun Pradhan

Mithun Pradhan

  • 1.6k
  • 150
  • 21.4k

Allow user to select only 5 items from syncfusion <ejs-listview

Sep 22 2023 6:24 AM

Allow user to select only 5 items and 6 item click to show message 'Only 5 items can be checked' not allow to click 6 item

My code

<ejs-listview id="listview" dataSource="@Model.TestListViewModel" showCheckBox="true" select="CheckListBoxItems">
    <e-listview-fieldsettings text="Title" id="Id">
    </e-listview-fieldsettings>
</ejs-listview>
<script type="text/javascript">
    function CheckListBoxItems(args) {
        let listview = document.getElementById("listview")["ej2_instances"][0];
        let selectedItems = listview.getSelectedItems();
        let maxSelection = 5;

        if (selectedItems.data.length > maxSelection) {
            args.isChecked = false;
            oomNotify("Only 5 items can be checked", "warning");
        }
    }
</script>

 


Answers (3)