【问题标题】:How to select all rows from Kendo grid using checkbox on header如何使用标题上的复选框从 Kendo 网格中选择所有行
【发布时间】:2017-11-01 03:44:44
【问题描述】:

我选择了剑道网格上的所有复选框。此复选框仅选择第一页,当您移动到页面时,它不会被选中。我想要的只是使用复选框从网格中选择所有行。如果网格上返回的行数为 500,则必须一键选中所有行,即复选框。我已经尝试了很多示例,但没有让它在 MVC Razor 上运行。

我已经尝试过很多这样的例子Example

@(Html.Kendo().Grid<Model>()
                .Name("Grid")
                .ToolBar(toolBar => toolBar.Template("<strong><a className='k-grid-toolbar-create' onClick='goToFunctionDownloadAllIpossFile()' href ='" + Url.Action("GetFileFromSession", "ConsolidatedPOSS", "https") + "?SeletectOrders=#= SeletectOrders#'" + "><button type='button' class='btn btn-primary'> Download Selected Orders </button></a></strong>"))
                .Columns(columns =>
                {
                columns.Bound(x => x.ordernumber).Title("Order Number");
                 columns.Template(@<text></text>).ClientTemplate("<input type='checkbox' id='chkId' #= selected ? checked='checked':'' # class='checkbox' />")
                .HeaderTemplate("<input type='checkbox' class='checkbox1' id='checkAll1' onclick='checkAll(this)'/>").Width(50);
                })
                .Pageable(pageable => pageable
                //.Refresh(true)
                .PageSizes(true)
                .ButtonCount(5))
                .Scrollable()
                .Filterable()
                .Sortable()
                .Resizable(resize => resize.Columns(true))
                .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(10)
                .ServerOperation(false)
                .Read(read => read.Action("Action", "Controller"))))

Javascript

function checkAll(ele) {
    alert();
    var state = $(ele).is(':checked');
    grid = $('#Grid').data('kendoGrid');

    datasource = grid.dataSource.view();
    //dataSource.pageSize(dataSource.total());
    $.each(grid.dataSource.view(), function ()
    {
        if (this['selected'] != state)
        {
            this.dirty = true;
        }  
        this['selected'] = state;
    });
    grid.refresh();
}

【问题讨论】:

    标签: javascript asp.net-mvc checkbox kendo-grid


    【解决方案1】:

    你为什么不试试这个(手风琴的例子,但你可以让它与你相关):

     columns:[
            {
                field: "Checkbox", filterable: false, title: "<input type=\'checkbox\' class='\selectAll\' data-bind='checked:Checkbox' style='margin-left:3px;' />", width: "35px",
                template: '<input type="checkbox" style="margin-left: 4px;" class="checkone" # if (!CheckboxEnabled){ # disabled # } # # if (Checkbox){ # checked # } # />', sortable: false
            },
     ],
    
    // set child checkbox values from parent checkbox
    var setChildCheckboxes = function (parent) {
        var childCheckboxes = parent.closest('fieldset').find('.accordion-inner :checkbox');
        var activeChildCheckboxes = parent.closest('fieldset').find('.accordion-inner :checkbox:not(:disabled)');
        if (childCheckboxes.length > 0) {
            if (activeChildCheckboxes.length > 0) {
                var checkedValue = (parent.attr("checked") == "checked") ? true : false;
                activeChildCheckboxes.prop('checked', checkedValue);
            } else {
                // Uncheck and disable parent checkbox if there are no active child checkboxes
                parent.attr('checked', false);
                parent.attr('disabled', true);
            }
        }
    };
    
    // select all checkboxes
    $('.checkall').on('click', function () {
        setChildCheckboxes($(this));
        // Enable/disable the action buttons
        if ($.find(':checkbox:checked').length > 0) {
            $("#push-button").attr("disabled", false);
        } else {
            $("#push-button").attr("disabled", true);
        }
    });
    

    【讨论】:

    • 如何像我发布的那样与剃须刀网格内的复选框挂钩?
    • 我为你添加了字段栏,有帮助吗?
    • 我无法理解它将如何在 kendo mvc Razor 上运行,因为您可以看到我的网格
    • 你可以不使用jquery吗?
    • 你能用你的网格制作剑道道场吗
    猜你喜欢
    • 2015-08-12
    • 2011-03-12
    • 2020-07-16
    • 2014-06-20
    • 2015-03-28
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多