|
Re: Deleting Rows in TableField not calling store [message #988922 is a reply to message #988884] |
Mon, 03 December 2012 17:58 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
In a Table on the client, you have two ways to delete a row:
* deleteRow(..): the row disappear from Table (as expected by the user), but is still present in the table. You can access it with ITableRow#getDeletedRows(). Later if you export the form content in the formData, you will get row in the table with the status ITableHolder.STATUS_DELETED and you can persist the deletion in the database:
for (int i = 0; i < formData.getStandardTable().getRowCount(); i++) {
if (formData.getStandardTable().getRowState(i) == ITableHolder.STATUS_DELETED) {
//persist the deletion in the database.
}
}
I often use a switch on getRowState(), because the action I need depend on the row status:
for (int i = 0; i < table.getRowCount(); i++) {
switch (table.getRowState(i)) {
case ITableHolder.STATUS_INSERTED:
//persist insertion
break;
case ITableHolder.STATUS_DELETED:
//persist deletion
break;
case ITableHolder.STATUS_UPDATED:
//persist modification
break;
case ITableHolder.STATUS_NON_CHANGED:
default:
//Do nothing
break;
}
}
* discardRow(..): the row is removed from the table and lost. Nothing is sent to the server.
Now if you set AutoDiscardOnDelete on the table, calling deleteRow(..) is equivalent to discardRow(..).
The semantic of a discarded row is: the row is deleted + there is no modification to commit to the server. The TableField assume there is no modifications. There is no "saveNeeded" status, the user will not be informed that he has pending modifications on the form...
This is why, in your case I recommend to set AutoDiscardOnDelete to false.
---
Now if you still want to discard a row, and to indicate to the form that you have a modification, you can
Now if for any reason you still want to discard a row, and in the same time indicate a pending modification you can:
* Call touch() on the TableField.
* Override the execIsSaveNeeded() on the TableField (this allow you to implement a custom calculation)
If you want to enforce a form store (like a OK or a SAVE button would do), instead of just indicating a modification on the form, I recommend you to call IForm#doSave() instead of AbstractForm#storeStateInternal(). The doSave() method will perform all the other checks (validations, custom checks...) in order to have a clean state of the form (and of the formData).
---
I hope this helps. Do not hesitate to continue the conversation if you need more informations.
|
|
|
|
Re: Deleting Rows in TableField not calling store [message #989003 is a reply to message #988937] |
Tue, 04 December 2012 09:39 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
The API of table in the client offers a lot of functions. In my opinion, 3 ways can be considered:
1: One row, with type check on set value. (you get compile error if you change something in your table):
ITableRow row = getTable().createRow();
getTable().getIntegerColumn().setValue(row, 25);
getTable().getTextColumn().setValue(row, "Dolore");
getTable().addRow(row, true); //true means mark as inserted. If you omit the second parameter, default is false.
2: One row as Object[] array.
getTable().addRowsByArray(
new Object[]{42, "Amet"},
ITableRow.STATUS_INSERTED); //You can omit the second parameter, default is ITableRow.STATUS_INSERTED.
3: Multiple rows as Object[][] array.
getTable().addRowsByMatrix(new Object[][]{
new Object[]{57, "Viverra"},
new Object[]{74, "Gravida"}
}, ITableRow.STATUS_INSERTED); //You can omit the second parameter, default is ITableRow.STATUS_INSERTED.
For the method 2 and 3 you need to be sure that the order of your array elements match with the order of your table columns.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02769 seconds