Need More Info
Last Updated: 20 Jan 2025 21:30 by ADMIN

I use the ASP.NET MVC widget code to add a ButtonGroup to a view. The ButtonGroup configuration has 2 buttons, has selection = many, and one of the buttons is selected. 


            @(Html.Kendo().ButtonGroup()
                .Name("select-data-source-filters")
                .HtmlAttributes(new { @class = "", @style = "text-align: center; flex-flow: row;"})
                .Selection("multiple")
                .Items(t =>
                {
                    t.Add().Text("Include Default Product Scenarios").Selected(false).HtmlAttributes(new { @id = "databaseItems", @class= "mb-2 k-ml-2.5" });
                    t.Add().Text("Include User Defined Product Scenarios").Selected(true).HtmlAttributes(new { @id = "userDefinedItems", @class = "mb-2 ml-2" });
                })
            )

 

In an event handler for a different widget (e.g., Grid), I programmatically select the button that is not yet selected. This should cause both buttons to now be selected. However, the act of getting a reference to the button group widget object causes the selection property to be reset to "single". The workaround is to manually reset the selection option to "multiple". 

                        let buttonGroupWidget = $("#select-data-source-filters").kendoButtonGroup().data("kendoButtonGroup");
                        if (debugLevel > 0) {
                            console.log(".... buttonGroupWidget = " + buttonGroupWidget + " : ", buttonGroupWidget);
                            console.log(".... (initial) buttonGroupWidget.selectedIndices = " + buttonGroupWidget.selectedIndices + " : ", buttonGroupWidget.selectedIndices);
                        }
                        if (buttonGroupWidget !== null && buttonGroupWidget !== undefined) {
                            buttonGroupWidget.options.selection = "multiple";//workaround for a bug in 2024Q3 that resets selection to single when get reference to the kendo widget
                            buttonGroupWidget.select(0);
                            buttonGroupWidget.trigger("select");
                            console.log(".... (updated) buttonGroupWidget.selectedIndices = " + buttonGroupWidget.selectedIndices + " : ", buttonGroupWidget.selectedIndices);
                        }