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

Custom Toolbar with Integrated Command Buttons

1 Answer 556 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anna
Top achievements
Rank 1
Anna asked on 02 Dec 2015, 03:50 AM

I have a grid that I'm using the default popup editing for. I also am using a custom toolbar template. What I'd like to do is use the "create" command that can usually be used in the toolbar, within my custom toolbar template. Is this possible? Below is my code and any help would be greatly appreciated!

 

<script type="text/x-kendo-template" id="template">
    <div class="toolbar">
        <span class="grid-heading">All Users</span>
        <span name="create" class="btn btn-link pull-right" id="createUser"><i class="fa fa-user-plus"></i> Add New</span>
    </div>
</script>
 
    var grid = $("#UserListGrid").kendoGrid({
        dataSource: viewModel.get("userDataSource"),
        sortable: true,
        pageable: true,
        scrollable: false,
        filterable: {
            extra: false
        },
        toolbar: kendo.template($("#template").html()),
        columns: [
            {
                field: "DisplayName", title: "Display Name", template: "#:DisplayName#"
            },
            {
                field: "Email", template: "#:Email#"
            },
            {
                field: "PhoneNumber", title: "Phone Number", template: "#:PhoneNumber#"
            },
            {
                command: [
                    { name: "edit", text: "Edit", className: 'small btn btn-link editUser', imageClass: 'fa fa-pencil' },
                    { name: "destroy", text: "Delete", className: 'small btn btn-link danger', imageClass: 'fa fa-trash' }],
                width: "160px"
            }
        ],
        editable: {
            mode: "popup",
            template: kendo.template($("#userEditor").html()),
            "confirmation": "Are you sure you want to delete this user?"
        },
        edit: function (e) {
            var editWindow = this.editable.element.data("kendoWindow");
            editWindow.wrapper.css({ width: 450 });
 
            e.container.find("#roleUpdate").kendoComboBox({
                dataTextField: "Name",
                dataValueField: "Id",
                placeholder: "--Select Value--",
                dataSource: new kendo.data.DataSource({
                    schema: {
                        model: {
                            id: "RoleId"
                        }
                    },
                    transport: {
                        read: {
                            url: "/User/GetAllRoles",
                            dataType: "json"
                        }
                    }
                })
            });
        }
 
    }).data("kendoGrid");

1 Answer, 1 is accepted

Sort by
0
Anna
Top achievements
Rank 1
answered on 02 Dec 2015, 06:22 PM

In case anyone is curious, we figured this out. I simply added the "k-grid-add" class to the Create button in my template, and viola! Problem solved. Code is below for reference:

 

<script type="text/x-kendo-template" id="template">
    <div class="toolbar">
        <span class="grid-heading">All Users</span>
        <span class="btn btn-link pull-right k-grid-add"><i class="fa fa-user-plus"></i> Add New</span>
    </div>
</script>

Tags
Grid
Asked by
Anna
Top achievements
Rank 1
Answers by
Anna
Top achievements
Rank 1
Share this question
or