如何更改Kendo网格中“主行单击的展开和折叠详细信息上的aria标签?

问题描述 投票:0回答:1

我想从Kendo网格中的“主行单击上的展开和折叠详细信息中更改aria标签”,但是Kendo似乎再次覆盖了更改的标签。作为测试,我创建了“ new-label”属性。正确插入。

如何正确更改咏叹调标签?

PS:由于wcag问题,我必须更改名称。

<!DOCTYPE html>
<html>
<head>
    <base href="http://demos.telerik.com/kendo-ui/grid/hierarchy">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1026/styles/kendo.common.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1026/styles/kendo.default.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1026/styles/kendo.default.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2017.3.1026/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2017.3.1026/js/kendo.all.min.js"></script>
    

</head>
<body>

        <div id="example">
            <div id="grid"></div>

            <script>
                $(document).ready(function() {
                    var element = $("#grid").kendoGrid({
                        dataSource: {
                            type: "odata",
                            transport: {
                                read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees"
                            },
                            pageSize: 6,
                            serverPaging: true,
                            serverSorting: true
                        },
                        height: 600,
                        sortable: true,
                        pageable: true,
                        detailInit: detailInit,
                        dataBound: function(e) {
                          var grid = e.sender;
                          
                          grid.tbody.find("tr.k-master-row").click(function(e){                            
                            var target = $(e.target);  
                            
                            if ((target.hasClass("k-i-collapse"))) {
                              target.attr('aria-label', 'Collapse new');
                              target.attr('new-label', 'Collapse new');
                              console.log("collapse");
                              return;
                            }       
                            
                            if ((target.hasClass("k-i-expand"))) {
                              target.attr("aria-label", "Expand new");
                              target.attr('new-label', 'Expand new');
                              console.log("expand");
                              return;
                            }  
                            
   
                          })
                          	
                        },
                        columns: [
                            {
                                field: "FirstName",
                                title: "First Name",
                                width: "110px"
                            },
                            {
                                field: "LastName",
                                title: "Last Name",
                                width: "110px"
                            },
                            {
                                field: "Country",
                                width: "110px"
                            },
                            {
                                field: "City",
                                width: "110px"
                            },
                            {
                                field: "Title"
                            }
                        ]
                    });
                });

                function detailInit(e) {
                    $("<div/>").appendTo(e.detailCell).kendoGrid({
                        dataSource: {
                            type: "odata",
                            transport: {
                                read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                            },
                            serverPaging: true,
                            serverSorting: true,
                            serverFiltering: true,
                            pageSize: 10,
                            filter: { field: "EmployeeID", operator: "eq", value: e.data.EmployeeID }
                        },
                        scrollable: false,
                        sortable: true,
                        pageable: true,
                        columns: [
                            { field: "OrderID", width: "110px" },
                            { field: "ShipCountry", title:"Ship Country", width: "110px" },
                            { field: "ShipAddress", title:"Ship Address" },
                            { field: "ShipName", title: "Ship Name", width: "300px" }
                        ]
                    });
                }
              
              
            </script>
        </div>


</body>
</html>
kendo-ui kendo-grid
1个回答
0
投票

我已经解决了(不好,但是很罕见)。

我假设初始化时所有行都折叠。我添加aria-expanded = "false"。我还设置了aria-label = "Open Translate"(将“打开翻译”更改为所需的文本)。

在dataBound中,我执行了一个不愿意的setTimeOut(不知道500ms是否足够,服务器响应时间等。)>

setTimeout (function () {
       target.attr ('aria-label', 'Open Translate');
}, 500);

<!DOCTYPE html>
<html>
<head>
    <base href="http://demos.telerik.com/kendo-ui/grid/hierarchy">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1026/styles/kendo.common.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1026/styles/kendo.default.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1026/styles/kendo.default.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2017.3.1026/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2017.3.1026/js/kendo.all.min.js"></script>
    

</head>
<body>

        <div id="example">
            <div id="grid"></div>

            <script>
                $(document).ready(function() {
                    var element = $("#grid").kendoGrid({
                        dataSource: {
                            type: "odata",
                            transport: {
                                read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees"
                            },
                            pageSize: 6,
                            serverPaging: true,
                            serverSorting: true
                        },
                        height: 600,
                        sortable: true,
                        pageable: true,
                        detailInit: detailInit,
                        dataBound: function(e) {
                          var grid = e.sender;
                            
                           $('.k-i-expand').attr('aria-expanded', 'false');
                           $('.k-i-expand').attr('aria-label', 'Open Translate');
                          
                           grid.tbody.find("tr.k-master-row").click(function(e){
                           var target = $(e.target);

                           if ((target.hasClass("k-i-collapse"))) {
                             target.attr('aria-expanded', 'false');
                             setTimeout(function() {
                               target.attr('aria-label', 'Open Translate');
                             }, 200);
                             return;
                           } else if ((target.hasClass("k-i-expand"))) {
                             target.attr('aria-expanded', 'true');
                             setTimeout(function() {
                               target.attr('aria-label', 'Close Translate');
                             }, 200);
                             return;
                           }

                         })
                          	
                        },
                        columns: [
                            {
                                field: "FirstName",
                                title: "First Name",
                                width: "110px"
                            },
                            {
                                field: "LastName",
                                title: "Last Name",
                                width: "110px"
                            },
                            {
                                field: "Country",
                                width: "110px"
                            },
                            {
                                field: "City",
                                width: "110px"
                            },
                            {
                                field: "Title"
                            }
                        ]
                    });
                });

                function detailInit(e) {
                    $("<div/>").appendTo(e.detailCell).kendoGrid({
                        dataSource: {
                            type: "odata",
                            transport: {
                                read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                            },
                            serverPaging: true,
                            serverSorting: true,
                            serverFiltering: true,
                            pageSize: 10,
                            filter: { field: "EmployeeID", operator: "eq", value: e.data.EmployeeID }
                        },
                        scrollable: false,
                        sortable: true,
                        pageable: true,
                        columns: [
                            { field: "OrderID", width: "110px" },
                            { field: "ShipCountry", title:"Ship Country", width: "110px" },
                            { field: "ShipAddress", title:"Ship Address" },
                            { field: "ShipName", title: "Ship Name", width: "300px" }
                        ]
                    });
                }
              
              
            </script>
        </div>


</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.