I have a table defined and want to set an initial value on newly created items depending on the filter (through datasource) that is applied to the table. When I do so, it works perfectly when creating a new item on right-clicking the table and select the create option in the menu that is shown.
When using the create button however, the initial value is not set.
This is my table definition:
<table id="chaptersTable"
editable="true"
width="100%">
<actions>
<action id="create"/>
<action id="edit"/>
<action id="remove"/>
</actions>
<columns>
<column id="chapterBook"
editable="true"
width="200"/>
<column id="chapterOrder"
editable="true"
width="75"/>
<column id="chapterTitle"
editable="true"/>
<column id="chapterIcon"
editable="true"
width="100"/>
</columns>
<rows datasource="chaptersDs"/>
<buttonsPanel id="buttonsPanel"
alwaysVisible="true">
<button caption="msg://create"
icon="font-icon:PLUS"
action="chaptersTable.create"/>
<button id="saveBtn"
caption="msg://save"
invoke="onSaveBtnClick"/>
</buttonsPanel>
</table>
This is the init from the screen controller:
@Override
public void init(Map<String, Object> params) {
// Get chapters for specific book
chaptersDs.setQuery("select e from base$Chapter e where e.chapterBook = '" + Book + "' order by e.chapterOrder asc");
chaptersDs.refresh();
// Set current book as default for newly created chapters
chaptersDs.addItemChangeListener(event -> {
Map<String, Object> values = new HashMap<>();
values.put("chapterBook", Books.fromId(Book));
chapCreateAction.setInitialValues(values);
});
}
I’m puzzled why the different events lead to different results. The create button calls upon the table create action, like the right-click on the table does as well.
What’s wrong here?