Customize multi-select overflow text

Hello,

I have a multi-select dropdown of countries. 

Instead of "6 selected"

I would like to have "6 countries selected"

How do I achieve that?




Attachment: SyncfusionBlazorApp1_4_2548213a_1cb5ce32.zip

13 Replies

UD UdhayaKumar Duraisamy Syncfusion Team September 28, 2022 02:30 PM UTC

Hi Pavel,


We can achieve the requested requirement using JSInterop and OnValueSelect, ValueRemoved events. Please refer to the below code snippet and sample for more details.


[index.razor]

@using Syncfusion.Blazor.DropDowns

@using System.Runtime.InteropServices

@inject IJSRuntime JSRuntime

 

<SfMultiSelect TValue="List<string>" TItem="Country" CssClass="@((MultiVal != null && MultiVal.Count > 0) ? VALUE_IS_PRESENT_CSS_CLASS : FILTER_DEFAULT_CSS_CLASS)" Placeholder="Countries" EnableChangeOnBlur="false" @bind-Value="@MultiVal" DataSource="@Countries" Mode="@VisualMode.CheckBox" ShowClearButton="true" AllowFiltering="false" PopupHeight="700px" PopupWidth="400px" Width="200px">

    <MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings>

    <MultiSelectEvents TValue="List<string>" TItem="Country" ValueChange="@ValueChanged" Created="@OnCreated" OnValueSelect="@OnValueSelecthandler" ValueRemoved="@ValueRemovedhandler"></MultiSelectEvents>

</SfMultiSelect>

@code {

    private async Task ValueRemovedhandler(RemoveEventArgs<Country> args)

    {

        await JSRuntime.InvokeAsync<object>("ChnageText");

    }

    private async Task OnValueSelecthandler(SelectEventArgs<Country> args)

    {

        await JSRuntime.InvokeAsync<object>("ChnageText");

    }

}


[Script]

function ChnageText() {

            setTimeout(function () {

                var el = document.getElementsByClassName('e-remain')[0];

                if (el != null) {

                    var myArray = el.innerHTML.split(" ");

                    el.innerHTML = myArray[0] + " Countries " + myArray[1];

                }

            },50);

        }


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp1_4-519981220


Kindly try the above suggestion and let us know if this meets your requirement.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D



PA Pavel September 28, 2022 07:27 PM UTC

Hello this solution works partly but when you click away from the multiselect,

the text goes back to the default "3 selected" instead of "3 countries selected"

I have attached a video recording of the issue.


Thank you


Attachment: Screen_Recording_20220928_at_12.20.41_PM_4bbb5f85.zip



UD UdhayaKumar Duraisamy Syncfusion Team September 29, 2022 08:48 AM UTC

Hi Pavel,


We can resolve the reported issue by calling the ‘ChnageText’ function in the blur event of the component. Please refer to the below sample for more details.


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp1_41166733089


Documentation : https://blazor.syncfusion.com/documentation/multiselect-dropdown/events#blur


Kindly try the above suggestion and let us know if this meets your requirement.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.

Regards,

Udhaya Kumar D




PA Pavel September 30, 2022 01:03 AM UTC

Great thank you! I have two more questions:

  1. How can I get this to work with 2 multi-selects on 1 page. this part of the code targets a common property
  2. e-remain
  3. Is there any way to get rid of the flicker seen every-time you focus away from the multi-select? Even no values are selected or deselected.


I have added a video reference


Thank you


Attachment: Screen_Recording_20220929_at_4.10.47_PM_e7f5efba.zip



UD UdhayaKumar Duraisamy Syncfusion Team October 2, 2022 05:50 AM UTC

Hi Pavel,


Query 1 :

How can I get this to work with 2 multi-selects on 1 page. this part of the code targets a common property

e-remain


By changing the below highlighted property we can able to modify the required MultiSelect component as per the requirement. Please refer to the below sample for more details.


var el = document.getElementsByClassName('e-remain')[0];


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp1_41580220517


Query 2 :

Is there any way to get rid of the flicker seen every-time you focus away from the multi-select? Even no values are selected or deselected


We have achieved the requested requirement at the sample level. We can’t change the e-remain before it appends in the DOM. So we have used a condition to check whether the e-remain is available or not. Based on that we have modified the e-remain class. So, the flicker will occur.


Regards,

Udhaya Kumar D




PA Pavel October 4, 2022 07:47 PM UTC

Query 1 :

How can I get this to work with 2 multi-selects on 1 page. this part of the code targets a common property

e-remain

____

This is still not working for me. I implemented the code a seen in the sample but the code is unpredictable. As selection of one multiselect will change the text on the other multiselect even though i changed the array like the sample.

var el = document.getElementsByClassName('e-remain')[1];

Please refer to screen recording and the code sample.


Thank you


Attachment: changeText_73d994d3.zip


UD UdhayaKumar Duraisamy Syncfusion Team October 5, 2022 04:27 PM UTC

Hi Pavel,


We are validating the requirement. We will update the further details in two business days (7th October 2022).


Regards,

Udhaya Kumar D



UD UdhayaKumar Duraisamy Syncfusion Team October 9, 2022 07:13 AM UTC

Hi Pavel,


We have created a sample to resolve the above-reported conflict and shared it below for reference. Please refer to the below sample for more details.


[Index.razor]

@using Syncfusion.Blazor.DropDowns

@using System.Runtime.InteropServices

@inject IJSRuntime JSRuntime

 

<SfMultiSelect ID="multi1" TValue="List<string>" TItem="Country" CssClass="sample1" Placeholder="Countries" EnableChangeOnBlur="false" @bind-Value="@MultiVal" DataSource="@Countries" Mode="@VisualMode.CheckBox" ShowClearButton="true" AllowFiltering="false" PopupHeight="700px" PopupWidth="400px" Width="200px">

    <MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings>

    <MultiSelectEvents TValue="List<string>" TItem="Country" Blur="BlurHandler" ValueChange="@ValueChanged" Created="@CreatedHandler1"></MultiSelectEvents>

</SfMultiSelect>

 

<hr />

<SfMultiSelect ID="multi2" TValue="List<string>" TItem="Country" CssClass="sample2" Placeholder="Countries" EnableChangeOnBlur="false" @bind-Value="@MultiVal2" DataSource="@Countries" Mode="@VisualMode.CheckBox" ShowClearButton="true" AllowFiltering="false" PopupHeight="700px" PopupWidth="400px" Width="200px">

    <MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings>

    <MultiSelectEvents TValue="List<string>" TItem="Country" Blur="BlurHandler2" ValueChange="@ValueChanged2" Created="@CreatedHandler2"></MultiSelectEvents>

</SfMultiSelect>

 

@code {

    private const string FILTER_DEFAULT_CSS_CLASS = "defaultClass";

    private const string VALUE_IS_PRESENT_CSS_CLASS = "selectedClass";

    public List<string> MultiVal { get; set; } = new List<string>() { };

    public List<string> MultiVal2 { get; set; } = new List<string>() { };

    public int multi1_SelectedItem;

    public int multi2_SelectedItem;

    protected override void OnInitialized()

    {

        MultiVal = new List<string>() { "AU", "CA" };

    }

    private void CreatedHandler1(Object args)

    {

        ValueChanged(new MultiSelectChangeEventArgs<List<string>> { Value = MultiVal });

    }

    private void CreatedHandler2(Object args)

    {

        ValueChanged2(new MultiSelectChangeEventArgs<List<string>> { Value = MultiVal2 });

    }

    private async Task BlurHandler(Object args)

    {

        await JSRuntime.InvokeAsync<object>("ChnageText", multi1_SelectedItem);

    }

    private async Task ValueChanged(MultiSelectChangeEventArgs<List<string>> arg)

    {

        multi1_SelectedItem = (arg.Value == null) ? 0 : arg.Value.Count;

        await JSRuntime.InvokeAsync<object>("ChnageText", multi1_SelectedItem);

 

    }

    private async Task ValueChanged2(MultiSelectChangeEventArgs<List<string>> arg)

    {

        multi2_SelectedItem = (arg.Value == null) ? 0 : arg.Value.Count;

        await JSRuntime.InvokeAsync<object>("ChangeText2", multi2_SelectedItem);

 

    }

 

    private async Task BlurHandler2()

    {

        await JSRuntime.InvokeAsync<object>("ChangeText2", multi2_SelectedItem);

    }

}


[script.js]

function ChnageText(x) {

            var el = document.getElementsByClassName('e-delim-values e-delim-view')[0];

            if (x == 0) {

                el.innerHTML = " ";

            }

            else {

                if (el.classList.contains('e-delim-hide')) {

                    el.classList.remove('e-delim-hide');

                }

                el.innerHTML = x + " Countries Selected"

            }

        }

        function ChangeText2(y) {

            var el = document.getElementsByClassName('e-delim-values e-delim-view')[1];

            if (y == 0) {

                el.innerHTML = " ";

            }

            else {

                if (el.classList.contains('e-delim-hide')) {

                    el.classList.remove('e-delim-hide');

                }

                el.innerHTML = y + " Countries Selected"

            }

        }


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp1_4_9-2035194294


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D



PA Pavel October 10, 2022 11:27 PM UTC

Hello, when I try to implement the code

I get "3 countries selected +3 more..."

Any way to prevent the e-remain class from displaying "+3 more..."




UD UdhayaKumar Duraisamy Syncfusion Team October 11, 2022 06:56 AM UTC

Hi Pavel,


We have validated the reported query on our end. Unfortunately, we couldn’t reproduce the reported issue as per your scenario. We have shared a video illustration for reference. Also, we request you to provide additional details about the issue as mentioned below, This will help us validate the issue further and provide you with a better solution.


1. Issue reproducing sample (or modify the previously shared sample as per your scenario).

2. Issue replication steps.

3. Video illustration of the issue.


Regards,

Udhaya Kumar D


Attachment: Demo_91_2b3d7c71.zip


PA Pavel October 11, 2022 07:09 PM UTC

I have attached a sample and a video recording identifying two issues:

  1. When user selects and deselects a value the text changes to "3 selected"




2. When user clicks away and then selects and deselects a value text show +3 more..



Attachment: overflowtext_8c90a833.zip


UD UdhayaKumar Duraisamy Syncfusion Team October 12, 2022 04:36 PM UTC

Hi Pavel,


We are validating the requirement. We will update the further details in two business days (14th October 2022).


Regards,

Udhaya Kumar D



UD UdhayaKumar Duraisamy Syncfusion Team October 16, 2022 03:38 PM UTC

Hi Pavel,


Sorry for the inconvenience caused.


By using the setTimeout function in the JSInterop we can solve the reported issue. Please refer to the below code snippet for more details.


function ChnageText(x) {

            setTimeout(function () {

                var el = document.getElementsByClassName('e-delim-values e-delim-view')[0];

                if (x == 0) {

                    el.innerHTML = " ";

                }

                else {

                    if (el.classList.contains('e-delim-hide')) {

                        el.classList.remove('e-delim-hide');

                    }

                    el.innerHTML = x + " Countries Selected"

                }

            }, 100);

        }



Regards,

Udhaya Kumar D


Loader.
Up arrow icon