How to check chip selected or not

I am displaying the chip list using the below code and execute the filter event. 

<ejs-chiplist id="chip-filterTags" selection="Single" click="FilterClasses" cssClass="e-primary">

 <e-chips>
@foreach (var product in (List<FilterTagInfo>)ViewBag.FilterTags)
{
 <e-chip text="@product.Name" value="@product.FilterTagID" enabled="true"></e-chip>
  }
</e-chips>
</ejs-chiplist>

And here is my filterClasses event.


function FilterClasses(e) {
var FilterTagInfo = {};

FilterTagInfo.FilterTagID = e.data.value;

FilterTagInfo.Name = e.text;

console.log(FilterTagInfo.FilterTagID);

console.log( FilterTagInfo.Name );

}

Now here comes my query. FOR EXAMPLE, CHECK THE BELOW LIST. 

LIST:-  ALL   MATHS   SCIENCE   GEOGRAPHY   ENVIRONMENT

1)  When FIRST TIME PAGE RUN AND CLICK ON CHIP, let's say MATHS in console.log, ​it displays MATHS AND ID OF THE MATHS 5.

2) Now when I, UN-CHECK MATHS, in console.log it again shows me MATHS AND ID OF THE MATHS 5. but I want to fire a condition if the user dis-select the same chip and ALSO NO CHIP is selected then PASS the ID value as 100 and CHIP TEXT as ALL.






5 Replies 1 reply marked as answer

SM Shalini Maragathavel Syncfusion Team September 9, 2021 11:32 AM UTC

Hi Harshida, 

Greetings from Syncfusion support. 

We checked your query and suspect that you need to check whether the chip item is selected or unselected in ChipList. You can achieve your requirement using the selected arguments of click event as demonstrated in the below code snippet. 
 
<ejs-chiplist id="chip-filterTags" click="FilterClasses"  selection="Single"> 
    . . .  
</ejs-chiplist> 
<script> 
    function FilterClasses(args) { 
        if (args.selected == true) {  //to check whether the chip is selected or not 
            var FilterTagInfo = {}; 
            FilterTagInfo.FilterTagID = args.data.value; 
            FilterTagInfo.Name = args.text; 
        } 
        else { 
            var FilterTagInfo = {}; 
            FilterTagInfo.FilterTagID = 100; 
            FilterTagInfo.Name = null; 
        }  
    } 
</script> 
 
Please find the below sample for your reference. 

API Link: https://ej2.syncfusion.com/javascript/documentation/api/chips/clickEventArgs/#selected

Please get back to us if you need further assistance.

Regards, 
Shalini M. 


Marked as answer

HP Harshida Parmar September 9, 2021 11:37 AM UTC

Hello 

Shalini,


Thank you very much for the code. I am trying to use the same logic but just forgot the specify the condition related to ==true.



Thanks 




KR Keerthana Rajendran Syncfusion Team September 9, 2021 11:56 AM UTC

Hi Harshida, 
 
Most welcome. We are glad to hear that the provided suggestions helped you. Please get back to us if you need any further assistance. We will be happy to assist you. 
 
Regards, 
Keerthana R. 



HP Harshida Parmar September 9, 2021 12:02 PM UTC

Hello 

Keerthana,


That is what the reason I generally prefer my Client to USE the synfusion, because of the forum gives me a perfect reply with the example. 


Again thank you very much. 



Thanks 



KR Keerthana Rajendran Syncfusion Team September 9, 2021 02:18 PM UTC

Hi Harshida, 
 
Most welcome and thanks for your valuable feedback. It’s our pleasure to assist you ​​​​​​​ 

Regards, 
Keerthana R. 


Loader.
Up arrow icon