-
Notifications
You must be signed in to change notification settings - Fork 7
How to work with tables

Use table actions, that assigned to the buttons in the standard screen to add a new value to the table.
Use the selectRow(By rowBy) method to select the particular row in the table. This method allows selecting by the following selectors (see the Java doc for details):
- Selectors#byText(String)
- Selectors#byCells(String...)
- Selectors#withText(String)
- Selectors#isSelected()
- Selectors#byRowIndex(int)
- Selectors#byIndex(int)
$c(Table.class, "<cuba-id>").selectRow(By rowBy);
After the row selecting you can open an entity for editing by using the 'Edit' button.
If there is a need to select several rows at the same time, then you can use the selectRows(By rowBy) method. This method works similar to the single row selection
$c(Table.class, "<cuba-id>").selectRows(By rowBy);
After the entity creation or editing, you may need to check that the changes were saved in the table. Use the getCell(By cellBy) method for this purpose.
This method allows selecting a particular cell using the following selectors (see the Java doc for details):
- Selectors#byText(String)
- Selectors#withText(String)
- Selectors#byClassName(String)
- Selectors#byRowIndex(int)
- Selectors#byRowColIndexes(int, int)
For example, the user's name was changed and you need to check that the changes are saved:
$c(Table.class, "<cuba-id>").getCell(By cellBy).shouldHave(exactText("<Text>"));
Let's assume, that you need to sort table data by the particular column. Use the sort() method for this purpose. This method has two arguments: column id and the sort direction.
Here columnId is the cubaId of the column, sort direction is an enumeration with the three values: ASCENDING, DESCENDING and NONE.
$c(Table.class, "<tableId>").sort("<columnId>", Table.SortDirection.DESCENDING);
Let's assume that you want to select all users with "Company" group:
$c(UserBrowser.class).usersTable.selectRows(withText("Company"));
The further instructions describe a more complicated example when we need to select all users with the same name and group:
$c(UserBrowser.class).usersTable
.selectRows(Selectors.byCells("Company", "Same User"));
The code provided below allows selecting the particular row by the cell and check, that this row contains the necessary text.
$c(UserBrowser.class).usersTable
.selectRow(Selectors.byCells("Administrator"))
.shouldHave(Condition.text("admin"));

DataGrid has the same methods for the row selection, sorting and cells checking as a Table. Also, DataGrid has methods for the header cell selecting and the method that returns details row information.
The further instructions describe how to check the visibility of the details row:
$c(DataGrid.class, "informationDataGrid").getDetailsRow()
.$(byXpath("//*[contains(@class, 'v-verticallayout')]"))
.shouldBe(visible);