首页 > 解决方案 > jsGrid中的自动调整大小的列

问题描述

我正在玩 jsGrid,只剩下一个问题要解决:当我定义网格列时,我为除一列之外的所有列指定宽度。

fields: [
    { name: "Name", type: "text", title: "Naziv"  },
    { name: "Mbs", type: "text", width: 24, title: "MBS"  },
    { name: "PB", type: "text", width: 23, title: "PB"  },
    { name: "OIB", type: "text", width: 34, title: "OIB"  },
    { name: "Country", type: "text", width: 35, title: "Država"  },
    { name: "City", type: "text", width: 35, title: "Grad"  },
    { name: "ActiveFrom", type: "text", width: 28, title: "Od"  },
    { name: "ActiveTo", type: "text", width: 28, title: "Do"  },
    { name: "Active", type: "checkbox", width:10, title: "A" }
],

问题是第一个字段设置为100px,然后浏览器根据指定的宽度计算所有列的宽度,导致浏览器窗口宽度变化时列宽发生变化。

我曾尝试将该列宽设置为“auto”和“*”,但随后,该列占据了表格的 90%,其他列的宽度为 10px(但 css 显示了我之前定义的宽度)

有谁知道这个问题的解决方案?

标签: javascriptjqueryjsgrid

解决方案


在尝试呈现表格之前,必须至少将一列宽度设置为“自动”。如果未设置宽度,则默认为 100 像素,从而破坏了所需的外观。

只是我的运气。我在如此琐碎的事情上浪费了一个小时,当我决定在这里提问时,我找到了解决方案并希望删除这个问题的耻辱。


推荐阅读