在多列中渲染 GXT RadioGroup 或 CheckBoxGroup 的元素?

发布于 2024-08-08 23:12:26 字数 370 浏览 15 评论 0原文

我正在寻找一种在布局中渲染 GXT (GWT-Ext) RadioGroup 或 CheckBoxGroup 元素的方法,而不是单列 (Orientation.VERTICAL) 或单行 (Orientation.HORIZONTAL)。我看到 在 ExtJS 3.0 中,RadioGroups 和 CheckBoxGroups 很容易呈现在多列。但是,GXT 中似乎无法访问该配置。我在这里缺少什么吗?如果没有“简单”的解决方案,有没有办法为 RadioGroup 或 CheckBoxGroup 编写自定义渲染器?

I am looking for a way to render the elements of a GXT (GWT-Ext) RadioGroup or CheckBoxGroup in a layout other than a single column (Orientation.VERTICAL) or a single row (Orientation.HORIZONTAL). I see that in ExtJS 3.0, RadioGroups and CheckBoxGroups are easily rendered in multiple columns. However, the configuration doesn't seem to be accessible in GXT. Is there something I'm missing here? If there is no "simple" solution, is there a way to write a custom renderer for a RadioGroup or CheckBoxGroup?

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

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

发布评论

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

评论(5

赤濁 2024-08-15 23:12:26

com.extjs.gxt.ui.client.widget.form.CheckBoxGroup 继承自 com.extjs.gxt.ui.client.widget.form.MultiField ,其上写着API 页面

在单行或单列中显示多个字段的字段。

所以我认为当谈到“简单”的解决方案时你运气不好。对于复选框,我认为您可以使用多个 CheckboxGroups 和 hbox/vbox 或列布局来伪造它,但我认为它不适用于多个 RadioGroup,因为分组 Radio 具有更多含义(就哪些无线电是互斥的而言)。

com.extjs.gxt.ui.client.widget.form.CheckBoxGroup inherits from com.extjs.gxt.ui.client.widget.form.MultiField which says on its API page says

A field that displays multiple fields in a single row or column.

So I think you're out of luck when it comes to a 'simple' solution. With checkboxes I think you could fake it with multiple CheckboxGroups and hbox/vbox or column layouts but I don't think it would work with multiple RadioGroup since grouping Radios has more meaning (in terms of which ones are mutual exclusive).

一身仙ぐ女味 2024-08-15 23:12:26

您可以为网格中的每一列实现 GridCellRenderer,其中每一列对应于一个单选组选项。这适用于 GXT:

public class MyRenderer implements GridCellRenderer {
    public Radio render(ModelData model, String columnChoice, ColumnData config,
            int rowIndex, int colIndex, ListStore store, Grid grid) {

        Something something = ((Something) model).getSomething();
        Radio radio = new Radio();
        // we want one radioGroup per row:
        radio.setName("radioButton" + rowIndex);
        // set value depending on some property in the model corresponding to a
        // column
        if (something != null && something.getChoice().equals(columnChoice)) {
            radio.setValue(true);
        }
        return radio;
    }
}

You could implement GridCellRenderer for each column in a grid, with each column corresponding to a radiogroup choice. This will work for GXT:

public class MyRenderer implements GridCellRenderer {
    public Radio render(ModelData model, String columnChoice, ColumnData config,
            int rowIndex, int colIndex, ListStore store, Grid grid) {

        Something something = ((Something) model).getSomething();
        Radio radio = new Radio();
        // we want one radioGroup per row:
        radio.setName("radioButton" + rowIndex);
        // set value depending on some property in the model corresponding to a
        // column
        if (something != null && something.getChoice().equals(columnChoice)) {
            radio.setValue(true);
        }
        return radio;
    }
}
成熟的代价 2024-08-15 23:12:26

在不知道您正在寻找的物品的最终分布的情况下,我不知道这是否适合您;但是,您是否想过:创建一个大型 RadioGroup 或 CheckBoxGroup,然后根据需要使各个单选按钮/复选框不可见以获得您想要的模式?

如果您正在寻找多列,例如三列,每列有四个按钮,则并排使用三组,每组四个按钮。然后为每个组(假设存在一个)编写一个 OnClick() 或 OnSelect() 事件来管理这三个组,就好像它们是一个组一样。对于复选框来说这应该是微不足道的,对于单选按钮来说则有点复杂,因为一次只能选择一个单选按钮。

 R-1  R-2  R-3
+---++---++---+
| o || o || o |
| o || o || o |
| o || o || o |
| o || o || o |
+---++---++---+

// psudocode

form.onLoad()
{
   r1.selected = none;
   r2.selected = none;
   r3.selected = none;
   selection = none;
}

r1.OnClick()
{
   selection = r1.selected;
   r2.selected = none;
   r3.selected = none;
}

r2.OnClick()
{
   r1.selected = none;
   selection = r2.selected;
   r3.selected = none;
}

r3.OnClick()
{
   r1.selected = none;
   r2.selected = none;
   selection = r3.selected;
}

Without knowing the final distribution of items you are looking for I do not know if this will work for you; however, have you thought of this: Create a large RadioGroup or CheckBoxGroup then make individual radio buttons/checkboxes invisible as required to get the pattern you want?

If you are looking for multiple columns, say three colums with four buttons each, then use three groups of four buttons, side by side. Then write an OnClick() or OnSelect() event for each group (assuming one exists) to manage the three groups as if they were one. This should be trivial for checkboxes and a bit more complicated for radiobuttons since only one radiobutton should be selected at a time.

 R-1  R-2  R-3
+---++---++---+
| o || o || o |
| o || o || o |
| o || o || o |
| o || o || o |
+---++---++---+

// psudocode

form.onLoad()
{
   r1.selected = none;
   r2.selected = none;
   r3.selected = none;
   selection = none;
}

r1.OnClick()
{
   selection = r1.selected;
   r2.selected = none;
   r3.selected = none;
}

r2.OnClick()
{
   r1.selected = none;
   selection = r2.selected;
   r3.selected = none;
}

r3.OnClick()
{
   r1.selected = none;
   r2.selected = none;
   selection = r3.selected;
}
伤痕我心 2024-08-15 23:12:26

我知道这个问题已经有两年了,但我找到了解决方案:-)。
重点是将 Radio 而不是 RadioButton 添加到面板中。一些例子:

    final RadioGroup outputType = new RadioGroup("outputType");

    Radio pdf = new Radio();
    Radio docx = new Radio();
    Radio rtf = new Radio();
    Radio ods = new Radio();

    outputType.add(pdf);
    outputType.add(docx);
    outputType.add(rtf);
    outputType.add(ods);

    //this goes
    panel.add(pdf);
    panel.add(docx);
    panel.add(rtf);
    panel.add(ods);

    //instead of this
    panel.add(outputType);

我希望它能帮助任何人:)

I know that question is 2 year old but I found solution :-).
The point is to add Radio not the RadioButton to the panel. Some example:

    final RadioGroup outputType = new RadioGroup("outputType");

    Radio pdf = new Radio();
    Radio docx = new Radio();
    Radio rtf = new Radio();
    Radio ods = new Radio();

    outputType.add(pdf);
    outputType.add(docx);
    outputType.add(rtf);
    outputType.add(ods);

    //this goes
    panel.add(pdf);
    panel.add(docx);
    panel.add(rtf);
    panel.add(ods);

    //instead of this
    panel.add(outputType);

I hope it will help anyone :)

负佳期 2024-08-15 23:12:26

这是类构造函数的简单示例,它应该扩展 MultiField<复选框>班级。

public MyClass (String[] items, int columnsNumber) {
    setOrientation(Style.Orientation.HORIZONTAL);
    setSpacing(0);

    if (items != null) {
        final CheckBoxGroup[] columns = createColumns(columnsNumber);
        int i = 0;
        for (String item : items) {
            CheckBox check = new CheckBox();
            check.setBoxLabel(item);
            columns[i++ % columnsNumber].add(check);
            CLogger.info("Checkbox added for: " + item);
        }
        for (CheckBoxGroup column : columns) {
            add(column);
        }
    }
}

private CheckBoxGroup[] createColumns(int columnsNumber) {
    CheckBoxGroup[] columns = new CheckBoxGroup[columnsNumber];
    for (int i = 0; i < columns.length; i++) {
        columns[i] = new CheckBoxGroup();
        columns[i].setOrientation(Style.Orientation.VERTICAL);
        columns[i].setSpacing(0);
    }
    return columns;
}

那是你想要的吗?

That's simple example of constructor of your class, that should extends MultiField< CheckBox > class.

public MyClass (String[] items, int columnsNumber) {
    setOrientation(Style.Orientation.HORIZONTAL);
    setSpacing(0);

    if (items != null) {
        final CheckBoxGroup[] columns = createColumns(columnsNumber);
        int i = 0;
        for (String item : items) {
            CheckBox check = new CheckBox();
            check.setBoxLabel(item);
            columns[i++ % columnsNumber].add(check);
            CLogger.info("Checkbox added for: " + item);
        }
        for (CheckBoxGroup column : columns) {
            add(column);
        }
    }
}

private CheckBoxGroup[] createColumns(int columnsNumber) {
    CheckBoxGroup[] columns = new CheckBoxGroup[columnsNumber];
    for (int i = 0; i < columns.length; i++) {
        columns[i] = new CheckBoxGroup();
        columns[i].setOrientation(Style.Orientation.VERTICAL);
        columns[i].setSpacing(0);
    }
    return columns;
}

Is that you want?

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