【问题标题】:How to set multiline column in kendo ui grid如何在剑道 UI 网格中设置多行列
【发布时间】:2016-11-06 23:23:56
【问题描述】:

我需要将剑道 ui 网格的一列设置为多行。

现在特定列中有很多数据,所以它被缩短了... 是否有可能使该列成为多行?

【问题讨论】:

    标签: css kendo-ui telerik kendo-grid telerik-grid


    【解决方案1】:

    您可以使用以下代码 sn-p 在 kendo ui 网格中设置多行列。

    <style>
        .breakWord20 {
            word-break: break-all !important;
            word-wrap: break-word !important;
            vertical-align: top;
        }
    
        .k-grid-header .k-header {
            overflow: visible !important;
            white-space: normal !important;
        }
    </style> 
    ......
    ......
     columns: [
                        {
                            field: "ProductNameProductNameProductNameProductNameProductName", headerAttributes: {
                                "class": "breakWord20"
                            }
                        },
    .......
    .......
    

    完整代码:-

    <!DOCTYPE html>
    <html>
    <head>
        <title>Jayesh Goyani</title>
        <style>
            .breakWord20 {
                word-break: break-all !important;
                word-wrap: break-word !important;
                vertical-align: top;
            }
    
            .k-grid-header .k-header {
                overflow: visible !important;
                white-space: normal !important;
            }
        </style> 
        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.2.504/styles/kendo.common-material.min.css" />
        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.2.504/styles/kendo.material.min.css" />
    
        <script src="https://kendo.cdn.telerik.com/2016.2.504/js/jquery.min.js"></script>
    
        <script src="https://kendo.cdn.telerik.com/2016.2.504/js/kendo.ui.core.min.js"></script>
        <script src="https://kendo.cdn.telerik.com/2016.2.504/js/kendo.all.min.js"></script>
        <!--<script src="//kendo.cdn.telerik.com/2016.2.504/js/kendo.timezones.min.js"></script>--> 
    </head>
    <body>
        <div id="grid"></div>
        <script>
            $(document).ready(function () {
    
                var products = [{
                    ProductID: 1,
                    ProductNameProductNameProductNameProductNameProductName: "Chai",
                    SupplierID: 1,
                    CategoryID: 1,
                    QuantityPerUnit: "10 boxes x 20 bags",
                    UnitPrice: 18.0000,
                    UnitsInStock: 39,
                    UnitsOnOrder: 0,
                    ReorderLevel: 10,
                    Discontinued: false,
                    Category: {
                        CategoryID: 1,
                        CategoryName: "Beverages",
                        Description: "Soft drinks, coffees, teas, beers, and ales"
                    }
                }, {
                    ProductID: 2,
                    ProductNameProductNameProductNameProductNameProductName: "Chang",
                    SupplierID: 1,
                    CategoryID: 1,
                    QuantityPerUnit: "24 - 12 oz bottles",
                    UnitPrice: 19.0000,
                    UnitsInStock: 17,
                    UnitsOnOrder: 40,
                    ReorderLevel: 25,
                    Discontinued: false,
                    Category: {
                        CategoryID: 1,
                        CategoryName: "Beverages",
                        Description: "Soft drinks, coffees, teas, beers, and ales"
                    }
                }, {
                    ProductID: 3,
                    ProductNameProductNameProductNameProductNameProductName: "Aniseed Syrup",
                    SupplierID: 1,
                    CategoryID: 2,
                    QuantityPerUnit: "12 - 550 ml bottles",
                    UnitPrice: 10.0000,
                    UnitsInStock: 13,
                    UnitsOnOrder: 70,
                    ReorderLevel: 25,
                    Discontinued: false,
                    Category: {
                        CategoryID: 2,
                        CategoryName: "Condiments",
                        Description: "Sweet and savory sauces, relishes, spreads, and seasonings"
                    }
                }, {
                    ProductID: 4,
                    ProductNameProductNameProductNameProductNameProductName: "Chef Anton's Cajun Seasoning",
                    SupplierID: 2,
                    CategoryID: 2,
                    QuantityPerUnit: "48 - 6 oz jars",
                    UnitPrice: 22.0000,
                    UnitsInStock: 53,
                    UnitsOnOrder: 0,
                    ReorderLevel: 0,
                    Discontinued: false,
                    Category: {
                        CategoryID: 2,
                        CategoryName: "Condiments",
                        Description: "Sweet and savory sauces, relishes, spreads, and seasonings"
                    }
                }, {
                    ProductID: 5,
                    ProductNameProductNameProductNameProductNameProductName: "Chef Anton's Gumbo Mix",
                    SupplierID: 2,
                    CategoryID: 2,
                    QuantityPerUnit: "36 boxes",
                    UnitPrice: 21.3500,
                    UnitsInStock: 0,
                    UnitsOnOrder: 0,
                    ReorderLevel: 0,
                    Discontinued: true,
                    Category: {
                        CategoryID: 2,
                        CategoryName: "Condiments",
                        Description: "Sweet and savory sauces, relishes, spreads, and seasonings"
                    }
                }];
    
                $("#grid").kendoGrid({
                    dataSource: {
                        data: products,
                        schema: {
                            model: {
                                id: "ProductID",
                                fields: {
                                    ProductID: { type: 'number' },
                                    UnitsInStock: { type: 'number' },
                                    ProductNameProductNameProductNameProductNameProductName: { type: 'string' },
                                    QuantityPerUnit: { type: 'string' },
                                    UnitPrice: { type: 'number' },
                                }
                            }
                        },
                    },
    
                    resizable: true,
                    columns: [
                        {
                            field: "ProductNameProductNameProductNameProductNameProductName", headerAttributes: {
                                "class": "breakWord20"
                            }
                        },
                        { field: "UnitsInStock", title: "UnitsInStock" },
                        { field: "QuantityPerUnit", title: "QuantityPerUnit" },
                        { field: "UnitPrice", title: "UnitPrice" },
                    ]
                }); 
            }); 
        </script> 
    </body>
    </html>
    

    如果有任何问题,请告诉我。

    【讨论】:

    • 我只需要设置列 css 属性 white-space: normal !important; ...感谢您的详细回答!
    【解决方案2】:

    是的,你可以!您可以设置 headerAttributes 或属性以在列定义中指定 colspan:

    http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.headerAttributes http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.attributes http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.width

    {
        field: "Your Field",
        title: "Your Title",
        attributes: { "colspan": 2 },
        headerAttributes: { "colspan": 2 }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 2016-06-04
      相关资源
      最近更新 更多