This is a migrated thread and some comments may be shown as answers.

Getting name of dropdown menu that filters grid

3 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Catherine
Top achievements
Rank 1
Catherine asked on 25 Jun 2018, 07:57 PM

Hi, I'm currently trying to filter a grid using an external component like the dropdown menu. I've used the instructions found in this form thread.

How would I pass the name of the drop down menu as well as the id or text data associated with the selection.

For example here is my current code:

Javascript

<script>
    var menuName
    var menuItem
    function additionalData(e) {
        return {
            item: menuName + " " + menuItem
        }
    }
    function onChange(e) {

         //What would I put here to get the name or id of the dropdown? id, name, &ct.toString() do not work

        menuName = this.name() 
        menuItem = this.text()
        var grid = $("#analogGrid").data("kendoGrid")
        grid.dataSource.read()
    }
</script>

 

Grid HTMLHelper

//...
.Read(read => read.Action("Analogs_ReadAsync", "Analogs").Data("additionalData"))
//...

 

Controller Action

public async Task<JsonResult> Analogs_ReadAsync([DataSourceRequest]DataSourceRequest request, string item) {...}

 

3 Answers, 1 is accepted

Sort by
0
Catherine
Top achievements
Rank 1
answered on 25 Jun 2018, 07:59 PM
I'm very sorry; I actually meant for this to be posted in the ASP.NET Core form.
0
Accepted
Alex Hajigeorgieva
Telerik team
answered on 27 Jun 2018, 01:49 PM
Hello, Catherine,

I moved the thread in the UI for ASP.NET Core forums for you, no need to worry.

The UI For ASP.NET Core and MVC wrappers take the Name() parameter and use it to generate the widget's HTML element id. So here is an example of how to take the existing instance of a wrapper generated Kendo UI widget:

@(Html.Kendo().DropDownList()
        .Name("myDropDown")
)
 
<script type="text/javascript">
   $(document).ready(function(){
     var dropdownlist = $("#myDropDown").data("kendoDropDownList");
            console.log(dropdownlist);
    });
</script>

However, it looks like the drop-down list already has a change handler, so you can grab it's instance there and it's value. For more information, the change event API is available at:

https://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist/events/change

function onChange(e){
 // var dropdownlist = this;
 //  var dropdownlist = e.sender;
 var dropdownName = e.sender.element.attr("id");
 var selectedItem = this.value();
}

Let me know if you need further assistance.

Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Catherine
Top achievements
Rank 1
answered on 29 Jun 2018, 12:59 PM
Thanks Alex! Sorry it took me awhile to mark your post as the answer, but I' got things working thanks to you.
Tags
Grid
Asked by
Catherine
Top achievements
Rank 1
Answers by
Catherine
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or