Kendo UI grid toolbar template Dropdown selector Error (textbox instead of dropdown)

巧了我就是萌 提交于 2019-12-13 03:58:22

问题


Example I've been looking into getting this to work but so far instead of a dropdown I get and empty textbox which doesn't do anything.

Below is my present code:-

@section js {
<script type="text/x-kendo-template" id="template">
    <div class="toolbar">
        <label class="category-label" for="external">Show checks by ex:</label>
        <input type="search" id="external" style="width: 230px"></input>
    </div>
</script>
<script type="text/javascript">
    var theGrid;
    $().ready(function () {
        $('#listDiv').kendoGrid({
            dataSource: {
                type: 'json',
                serverPaging: true,
                pageSize: 10,
                transport: {
                    read: {
                        url: '@Url.Action("_IList", "Entry", new { @ExId = Model.ExId })',
                        data: { ignore: Math.random() }
                    }
                },
                schema: {
                    model: {
                        id: 'Id',
                        fields: {
                            Id: { type: 'number' },
                            Name: { type: 'string' },
                            Ex: { type: 'string' },
                            Date: { type: 'string' },
                            Check1: { type: 'string' },
                            Check2: { type: 'string' },
                            Check3: { type: 'string' },
                            Check4: { type: 'string' },
                            Check5: { type: 'string' },
                            Edit: { type: 'string' }
                        }
                    },
                    data: "Data",
                    total: "Count"
                }
            },
            scrollable: false,
            toolbar: kendo.template($("#template").html()),
            columns:
                [
                    {
                        field: 'Name'
                    },
                    {
                        field: 'Ex'
                    },
                    {
                        field: 'Date'
                    },
                    {
                        template: '#=Template1#' + sitePath + '#=Patient1#',
                        field: 'Patient1',
                        title: 'Patient 1',
                        width: 50
                    },
                    {
                        template: '#=Template2#' + sitePath + '#=Patient2#',
                        field: 'Patient2',
                        title: 'Patient 2',
                        width: 50
                    },
                    {
                        template: '#=Template3#' + sitePath + '#=Patient3#',
                        field: 'Patient3',
                        title: 'Patient 3',
                        width: 50
                    },
                    {
                        template: '#=Template4#' + sitePath + '#=Patient4#',
                        field: 'Patient4',
                        title: 'Patient 4',
                        width: 50
                    },
                    {
                        template: '#=Template5#' + sitePath + '#=Patient5#',
                        field: 'Patient5',
                        title: 'Patient 5',
                        width: 50
                    }

                ],
            pageable: true
        });
        var dropDown = grid.find("#external").kendoDropDownList({
            dataTextField: "ExName",
            dataValueField: "ExId",
            autoBind: false,
            optionLabel: "All",
            dataSource: {
                type: "json",
                severFiltering: true,
                transport: {
                    url: '@Url.Action("_Ex", "Entry")',
                    data: { ignore: Math.random() }
                }
            },
            change: function () {
                var value = this.value();
                if (value) {
                    grid.data("kendoGrid").dataSource.filter({ field: "ExId", operator: "eq", value: parseString(value) });
                } else {
                    grid.data("kendoGrid").dataSource.filter({});
                }
            }
        });
        theGrid = $('#listDiv').data('kendoGrid');
    });        
</script>
<style scoped="scoped">
    #grid .k-toolbar
    {
        min-height: 27px;
    }
    .external-label
    {
        vertical-align: middle;
        padding-right: .5em;
    }
    #external
    {
        vertical-align: middle;
    }
    .toolbar {
        float: right;
        margin-right: .8em;
    }
</style>
}
<h2>Check Lists</h2>

<div id="listDiv"></div>
<br />

It works to display all check lists for each Ex which I can select on a previous page and pass in the string Id to this one but I'd like to be able to figure out what's wrong with with the toolbar template as having the functionality on 1 page rather than spread over 2 is far more desirable.

Any help/guidance will be much appreciated.

Edit:

I did also find someone else who encountered the problem except they didn't get a forum response. Example 2


回答1:


You mention that somebody else encountered the problem and didn't receive a response, however the linked forum thread does contain a response and an answer to this issue. In that particular case a Javascript error had occurred on the page which prevented the dropdown from initializing correctly and I believe this is also the case for yourself.

Although not completely working because there isn't a valid datasource, I took your example code and dumped it into a jsFiddle and (after fixing some JS errors) you can see that the dropdown appears absolutely fine.

In particular, there were errors regarding grid and sitePath not being defined that prevented the dropdown from initializing.

    var grid;
    var sitePath = '';
    $().ready(function () {
        grid = $('#listDiv').kendoGrid({
            dataSource: {
                type: 'json',
                serverPaging: true,
                pageSize: 10,
                transport: {
                    read: {
                        url: '',
                        data: { ignore: Math.random() }
                    }
                },
                schema: {
                    model: {
                        id: 'Id',
                        fields: {
                            Id: { type: 'number' },
                            Name: { type: 'string' },
                            Ex: { type: 'string' },
                            Date: { type: 'string' },
                            Check1: { type: 'string' },
                            Check2: { type: 'string' },
                            Check3: { type: 'string' },
                            Check4: { type: 'string' },
                            Check5: { type: 'string' },
                            Edit: { type: 'string' }
                        }
                    },
                    data: "Data",
                    total: "Count"
                }
            },
            scrollable: false,
            toolbar: kendo.template($("#template").html()),
            columns:
                [
                    {
                        field: 'Name'
                    },
                    {
                        field: 'Ex'
                    },
                    {
                        field: 'Date'
                    },
                    {
                        template: '#=Template1#' + sitePath + '#=Patient1#',
                        field: 'Patient1',
                        title: 'Patient 1',
                        width: 50
                    },
                    {
                        template: '#=Template2#' + sitePath + '#=Patient2#',
                        field: 'Patient2',
                        title: 'Patient 2',
                        width: 50
                    },
                    {
                        template: '#=Template3#' + sitePath + '#=Patient3#',
                        field: 'Patient3',
                        title: 'Patient 3',
                        width: 50
                    },
                    {
                        template: '#=Template4#' + sitePath + '#=Patient4#',
                        field: 'Patient4',
                        title: 'Patient 4',
                        width: 50
                    },
                    {
                        template: '#=Template5#' + sitePath + '#=Patient5#',
                        field: 'Patient5',
                        title: 'Patient 5',
                        width: 50
                    }

                ],
            pageable: true
        });
        var dropDown = grid.find("#external").kendoDropDownList({
            dataTextField: "ExName",
            dataValueField: "ExId",
            autoBind: false,
            optionLabel: "All",
            dataSource: {
                type: "json",
                severFiltering: true,
                transport: {
                    url: '@Url.Action("_Ex", "Entry")',
                    data: { ignore: Math.random() }
                }
            },
            change: function () {
                var value = this.value();
                if (value) {
                    grid.data("kendoGrid").dataSource.filter({ field: "ExId", operator: "eq", value: parseString(value) });
                } else {
                    grid.data("kendoGrid").dataSource.filter({});
                }
            }
        });
        theGrid = $('#listDiv').data('kendoGrid');
    });     


来源:https://stackoverflow.com/questions/15357182/kendo-ui-grid-toolbar-template-dropdown-selector-error-textbox-instead-of-dropd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!