do you have API's to select/unselect all items in Listview

do you have API's to select/unselect all items in Listview. Please assist


3 Replies 1 reply marked as answer

SA SureshRajan Alagarsamy Syncfusion Team October 9, 2023 01:49 PM UTC

Hi Mahesh,


We have reviewed your query and understand your requirement to select and unselect all items within the ListView component. To address this, we recommend enabling checkboxes for the ListView items. Additionally, we have integrated two Buttons, one for checking and one for unchecking, and bound “click” events to these buttons.


When you click the "Check" button, you will notice that all ListView items are selected. We have achieved this functionality using the "checkAllItems" method. Similarly, when clicking the "Uncheck" button, all items will be unchecked, and this is accomplished using the "uncheckAllItems" method.


Refer to the below code snippet for further reference.


[Index.cshtml]

 

....

 

<div id="flat-list">

    <h4>Flat List</h4>

    <!-- ListView element -->

    <ejs-listview enable="true" id="listview" dataSource="data" showCheckBox=true>

    </ejs-listview>

</div>

 

<ejs-button id="checkbtn" content="Check"></ejs-button>

<br />

<ejs-button id="uncheckbtn" content="UnCheck"></ejs-button>

 

<script>

    document.getElementById('checkbtn').addEventListener('click', () => {

        document.getElementsByClassName('e-listview')[0].ej2_instances[0].checkAllItems();

    });

    document.getElementById('uncheckbtn').addEventListener('click', () => {

        document.getElementsByClassName('e-listview')[0].ej2_instances[0].uncheckAllItems();

    });

</script>


Check out the attached sample and get back to us if you need any further assistance.


Regards,
Suresh.


Attachment: CoreListView_Sample_1dc9475b.zip

Marked as answer

JZ Javad Zh December 25, 2024 07:27 AM UTC

Thank you 



KG Kalpana Ganesan Syncfusion Team December 26, 2024 05:40 AM UTC

Hi Javad,

You are welcome. Please get back for further assistance.

Regards,

Kalpana.


Loader.
Up arrow icon