简体   繁体   English

在WLISTBOX ZK中选择行时,如何设置可编辑的单元格?

[英]How to set a cell editable when row is selected in WLISTBOX ZK?

我想在ZK框架的WLISTBOX中选择行时使特定的单元格可编辑吗?

Because there was no answer of you wanted it MVVM or MVC I decided to go for MVVM. 因为您没有想要MVVM或MVC的答案,所以我决定选择MVVM。

Here is a working fiddle. 这是一个工作的小提琴。
I'm pasting the most important code here for when the link shouldn't work anymore : 我在这里粘贴最重要的代码,以了解何时该链接不再可用:

<listbox model="@load(vm.items)" selectedItem="@bind(vm.selected)" hflex="true" height="300px">
    <listhead>
        <listheader label="Name" width="80px"/>
        <listheader label="Price" align="center" width="80px" />
        <listheader label="Quantity" align="center" width="80px" />
    </listhead>
    <template name="model" var="item">
        <listitem >
            <listcell>
                <label visible="@load(vm.selected ne item)" value="@load(item.name)" />
                <textbox visible="@load(vm.selected eq item)" value="@bind(item.name)" />
            </listcell>
            <listcell>
                <label visible="@load(vm.selected ne item)" value="@load(item.price)" />
                <intbox visible="@load(vm.selected eq item)" readonly="true" value="@bind(item.price)" />
            </listcell>
            <listcell>
                <label visible="@load(vm.selected ne item)" value="@load(item.quantity)" />
                <intbox visible="@load(vm.selected eq item)" readonly="true" value="@bind(item.quantity)" />
            </listcell>
        </listitem>
    </template>
</listbox>

Little explication, if working previous ZK 8 you can use this. 很少说明,如果使用以前的ZK 8,则可以使用它。
So we check in the zul if the selected item equals ( eq ) or don't equals ( ne ) to the rendered item. 因此,我们在zul中检查所选项目是否等于( eq )或不等于( ne )与渲染的项目。
We change the visibility of that component then. 然后,我们更改该组件的可见性。
If working ZK8 or higher you can use the <if test="load(vm.selected eq item)"> . 如果使用ZK8或更高版本,则可以使用<if test="load(vm.selected eq item)">
With this it's working with shadow elements and the condition what isn't true will not be rendered(not in the DOM), while working with visible it will be in the DOM. 有了它,它就可以处理阴影元素,不正确的条件将不会被渲染(不在DOM中),而可见的情况将在DOM中得到。

Use the if attribute in early ZK8 only in combination with ${} expressions, the MVVM syntax won't work. 在早期ZK8中仅将if 属性${}表达式结合使用,MVVM语法将不起作用。
And because it's only static you can't use it to switch realtime. 而且因为它只是静态的,所以您不能使用它来实时切换。
So that's the reason why we need to use visible attribute. 这就是为什么我们需要使用visible属性的原因。

This is a late response but worth recording none the less. 这是一个较晚的响应,但仍然值得记录。

In the ADempiere implementation of ZK, the WListbox uses the WListBoxRenderer to render the rows and all the cells in the row. 在ZK的ADempiere实现中,WListbox使用WListBoxRenderer渲染行和行中的所有单元格。 The class of each column is defined and applied to all rows, making the rows identical. 定义每列的类并将其应用于所有行,从而使行相同。 The WListBoxRenderer uses this class to determine which component to use to display the field and which to use to edit the field. WListBoxRenderer使用此类确定用于显示字段的组件和用于编辑字段的组件。 The editor is only enabled if the column is defined as read/write when the table is initialized. 仅当初始化表时将列定义为可读写时,才启用编辑器。 You can do this using the ColumnInfo structure or through the setColumnClass() and setColumnReadWrite() methods shown below. 您可以使用ColumnInfo结构或通过下面显示的setColumnClass()和setColumnReadWrite()方法来执行此操作。

/**
 * Set the attributes of the column.
 *
 * @param index     The index of the column to be modified
 * @param classType The class of data that the column will contain
 * @param readOnly  Whether the data in the column is read only
 * @param header    The header text for the column
 *
 * @see #setColumnClass(int, Class, boolean)
 */
public void setColumnClass (int index, Class classType, boolean readOnly, String header)
{
    WListItemRenderer renderer = (WListItemRenderer)getItemRenderer();

    setColumnReadOnly(index, readOnly);

    renderer.setColumnHeader(index, header);

    renderer.setColumnClass(index, classType);

    if (index < m_modelHeaderClass.size())
        m_modelHeaderClass.set(index, classType);
    else
        m_modelHeaderClass.add(classType);

    return;
}

/**
 *  Set Column at the specified <code>index</code> to read-only or read/write.
 *
 *  @param index    index of column to set as read-only (or not)
 *  @param readOnly Read only value. If <code>true</code> column is read only,
 *                  if <code>false</code> column is read-write
 */
public void setColumnReadOnly (int index, boolean readOnly)
{
    Integer indexObject = new Integer(index);

    //  Column is ReadWrite
    if (m_readWriteColumn.contains(indexObject))
    {
        //  Remove from list
        if (readOnly)
        {
            m_readWriteColumn.remove(indexObject);
        }   //  ReadOnly
    }
    //  current column is R/O - ReadWrite - add to list
    else if (!readOnly)
    {
        m_readWriteColumn.add(indexObject);
    }

    return;
}   //  setColumnReadOnly

Here is an example used to show the invoices in the Payment Allocation form. 这是一个用于在“付款分配”表单中显示发票的示例。 The IMiniTable interface is implemented by the WListBox class. IMiniTable接口由WListBox类实现。 Note that three of the columns are set readOnly=false so those cells are editable in the table. 请注意,其中三列设置为readOnly = false,因此这些单元格在表中是可编辑的。

public void setInvoiceColumnClass(IMiniTable invoiceTable, boolean isMultiCurrency)
{
    Vector<String> names = getInvoiceColumnNames(isMultiCurrency);
    int i = 0;
    invoiceTable.setKeyColumnIndex(i);
    invoiceTable.setColumnClass(i, IDColumn.class, true, names.get(i++));        //  0-C_Invoice_ID
    invoiceTable.setColumnClass(i, Timestamp.class, true, names.get(i++));        //  1-TrxDate
    invoiceTable.setColumnClass(i, String.class, true, names.get(i++));           //  2-Value
    if (isMultiCurrency)
    {
        invoiceTable.setColumnClass(i, String.class, true, names.get(i++));       //  3-Currency
        invoiceTable.setColumnClass(i, BigDecimal.class, true, names.get(i++));   //  4-Amt
    }
    invoiceTable.setColumnClass(i, BigDecimal.class, true, names.get(i++));       //  5-ConvAmt
    invoiceTable.setColumnClass(i, BigDecimal.class, true, names.get(i++));       //  6-ConvAmt Open
    invoiceTable.setColumnClass(i, BigDecimal.class, false, names.get(i++));      //  7-Conv Discount
    invoiceTable.setColumnClass(i, BigDecimal.class, false, names.get(i++));      //  8-Conv WriteOff
    invoiceTable.setColumnClass(i, BigDecimal.class, false, names.get(i++));      //  9-Conv Applied
    invoiceTable.setColumnClass(i, BigDecimal.class, true, names.get(i++));     //  10-Conv OverUnder
    //  Table UI
    invoiceTable.autoSize();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM