如何以百分比指定光滑网格的宽度?

发布于 2024-09-06 13:21:11 字数 255 浏览 5 评论 0原文

有人知道如何以百分比设置网格宽度吗?

例如 但页面中网格的宽度超过2000像素。它不会根据页面宽度进行调整。

任何帮助将不胜感激。

谢谢 帕德马纳班

Is anybody knows how to set width of the grid in percentage?

for example

but in the page the width of grid is more than 2000 pixels. It does not get adjusted to page width.

Any help would be appreciated.

Thanks
Padmanabhan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

舞袖。长 2024-09-13 13:21:11

我发现这个问题确实很老了,但是我在尝试弄清楚如何让我的列占据表格的整个宽度时遇到了这个问题。希望有一天它能帮助别人。

我无法弄清楚如何显式设置列宽,但我确实让它隐式工作。

操作方法如下:

首先在列声明中添加 width: 300 (或您想要的任何宽度),

{id:"name", name:"Student Name", field:"firstName", width: 300}

为所有列设置此值,您想要更宽的列放置更大的数字,例如 500,

然后在您的选项声明添加 forceFitColumns: true

{enableCellNavigation: true, enableColumnReorder: false, forceFitColumns: true};

通过这样做,我能够让我的表列占用表的剩余空间,并保持我想要的相对于彼此的部分。

i see that this question is really old, but i came across this question while trying to figure out how to get my columns to take up the full width of the table. hopefully it'll help someone someday.

i couldn't figure out how to set the column widths explicitly but i did get it to work implicitly.

here's how to do it:

first in your column declaration add width: 300 (or whatever width you want)

{id:"name", name:"Student Name", field:"firstName", width: 300}

set this for all your columns, the ones you want wider put a bigger number, e.g. 500

then in your options declation add forceFitColumns: true

{enableCellNavigation: true, enableColumnReorder: false, forceFitColumns: true};

by doing this i was able to get my table columns to take up the remaining space of the table, and maintain the portions i want relative to each other.

念三年u 2024-09-13 13:21:11

我有一个功能可以调整网格大小。

    function resizeGrid(newsize, grid) {
            $('#dataGrid').css('width', newsize);
            grid.resizeCanvas();
    }

不要忘记将 forceFitColumns: true 添加到网格选项中,如 conman 上面所述

I have a function to do a grid resize.

    function resizeGrid(newsize, grid) {
            $('#dataGrid').css('width', newsize);
            grid.resizeCanvas();
    }

Don't forget to add forceFitColumns: true to your grid options as conman says above

放我走吧 2024-09-13 13:21:11

仅供参考,这似乎在 SlickGrid 的最新版本中可以开箱即用。 :)

FYI, this appears to work out of the box in recent versions of SlickGrid. :)

他是夢罘是命 2024-09-13 13:21:11

是的,这是可能的,但我找不到简单的解决方案。
所以你必须对其进行大量定制。

我目前正在为此研究解决方案。
这是一个有效的示例,但它确实有一些错误。其中一些来自 jsfiddle 设置。
http://jsfiddle.net/MQBLn/8/

基本上我创建了一个基于单元格格式的函数在列标题尺寸上。
然后只要有一个 Action 就必须调用该函数。 (排序、调整大小等)
另外,我确实必须对 slick.grid.js 进行一些小的更改,因此您会发现它加载在 JS 部分的顶部,然后是自定义 js。然后一些CSS的覆盖规则。

这是我的单元格格式化程序功能,

function formatCells(grid)
{
    var columns = grid.getColumns();
    var grid_width = grid.getGridPosition().width;
    var header = $(".slick-header-columns");

    for(var i in columns)
    {
        $(".slick-cell.r"+i).css("width", (Math.floor(((header.children().eq(parseFloat(i)).width()+9)/(grid_width-_scrollBarWidth))*10000)/100)+"%");
    }
}

我希望它有用,也许有一天会作为一项设置内置到 SlickGrid 中。

Yes, it is possible, but I can not find an easy solution.
So you have to customize it quite a bit.

I am currently working on a solution for this.
Here is a working example, but it does have a few bugs. Some of which are from jsfiddle setup.
http://jsfiddle.net/MQBLn/8/

basically I created a function that formats the cells based on the Column Heading Sizes.
Then you have to call that function whenever there is an Action. (Sort, Resize, Etc.)
Also I did have to make some minor changes to slick.grid.js So you will find it loaded at the top of JS section followed by custom js. Then some overwrite rules for css.

Here is my Cell Formatter Function

function formatCells(grid)
{
    var columns = grid.getColumns();
    var grid_width = grid.getGridPosition().width;
    var header = $(".slick-header-columns");

    for(var i in columns)
    {
        $(".slick-cell.r"+i).css("width", (Math.floor(((header.children().eq(parseFloat(i)).width()+9)/(grid_width-_scrollBarWidth))*10000)/100)+"%");
    }
}

I hope this is usefull and maybe one day built into SlickGrid as a setting.

掩于岁月 2024-09-13 13:21:11

SlickGrid 格式化程序为您提供 5 个参数:

formatter: function ( row, cell, value, columnDef, dataContext )

您可以使用 dataContext 参数在特定格式化程序等中调整列的宽度:dataContext.width = 600 使特定列为 600px。

示例

    {
        /* Categories */
        id: "categories",
        formatter: function ( row, cell, value, columnDef, dataContext ) {
            var html = '';

            if ( value.indexOf( 'variation-child' ) != -1 ) {
                return value;
            } else if ( value ) {
                for ( var i = 0; i < value.length; i++ ) {
                    if ( value[ i ] ) {
                        html += '<div class="box category-box" title="' + value[ i ] + '">' + value[ i ] + '</div>';
                    }
                }
            }

            columnDef.width = 600 * value.length;

            return html;
        },
        name: "Categories", field: "categories", sortable: true, editor: Slick.Editors.TaxonomyPopupEditor
    }

每当向网格添加数据后,请记住使用 grid.resizeCanvas(); (重新计算宽度)。

The SlickGrid-formatter supply you with 5 parameters:

formatter: function ( row, cell, value, columnDef, dataContext )

You can adjust the columns' width using the dataContext parameter, within the specific formatter, etc: dataContext.width = 600 makes the specific column 600px.

Example

    {
        /* Categories */
        id: "categories",
        formatter: function ( row, cell, value, columnDef, dataContext ) {
            var html = '';

            if ( value.indexOf( 'variation-child' ) != -1 ) {
                return value;
            } else if ( value ) {
                for ( var i = 0; i < value.length; i++ ) {
                    if ( value[ i ] ) {
                        html += '<div class="box category-box" title="' + value[ i ] + '">' + value[ i ] + '</div>';
                    }
                }
            }

            columnDef.width = 600 * value.length;

            return html;
        },
        name: "Categories", field: "categories", sortable: true, editor: Slick.Editors.TaxonomyPopupEditor
    }

Remember to use grid.resizeCanvas(); (recalculate the widths), whenever you're done adding data to the grid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文