K2BTools Tutorial - Exercise 5.2: Multirow actions

In-Grid actions apply only to the row they are located in. In other scenarios, you may want the user to select several lines and apply an action to all of them.

In this example you will add an option to change the status of a set of customers, instead of changing the status of one customer at a time. You will have to implement a procedure in order to do that, based on the following instructions.

Row Selection Multiple: Basic Usage

  1. Open the Customer transaction and go to the K2BEntityServices pattern definition.
  2. Find the “WorkWith” node, and the “Actions” node inside it.
  3. Add an action in the “Actions” node, and set the following properties:
    1. “Control Name (Id)” to “ChangeSelectedCustomersStatus”
    2. “Position” to “Bottom”
    3. “Caption” to “Change State”
    4. “Row Selection” to “Multiple”
  4. Save and apply the pattern.
  5. Go to the Pattern object in the folder view, and see the objects generated. You should find an SDT called “WWCustomerSDT”. Open it and analyze its structure.
    Generated Objects

  6. Implement a procedure that receives the a variable with type “WWCustomerSDT” as a parameter and changes the customer status for all items of the collection. You can do so by doing this:
    1. Create a new procedure called “ChangeSelectedCustomersStatus”.
    2. Define a variable called “SelectedCustomers” with type “WWCustomerSDT”.
    3. Define a variable called “SelectedCustomer” with type “WWCustomerSDT.WWCustomerSDTItem”.

    4. Add a parm to receive the “&SelectedCustomers” variable value.

    5. Add code in the “Source” part to implement the action.

  7. Return to the action created in step 3, and set the “GXObject” property to “ChangeSelectedCustomersStatus”.
  8. Save, generate, and execute your app. Test the action in the Customer Work With. You must select an item to execute the action.

Row Selection Persistence

By default the selected rows of the grid are persisted when the user changes the page of the grid. To see this follow these steps:

  1. In the Web Panel select some customers and go to the next page in the grid.
  2. Select some customers on the second page.
  3. Return to the previous page an see how the customers remain selected.
  4. Try to search for a customer using the filters available in the screen.
  5. Clear the filters.
  6. See how the customers ramin selected.

Row Selection Scope: All Selected Rows

By default actions with "Row Selection" = "Multiple" apply to all the rows that were selected by the user, regardless of the page that is currently being shown. You can change this behaviour by modifying the "Row Selection Scope" property located in the action. In the following part you will see how the "All Selected Rows" scope works.

  1. In runtime, select customers from two different pages, apply the action and see how the customer state is changed in both pages.
  2. Select some customers, search for a customer, and then apply the action (without clearing the filters) and see how the action is applyed to all selected customers.

Row Selection Scope: OnlyVisibleRows

You will now see how "Row Selection Scope" = "OnlyVisibleRows" works.

  1. In the EntityServices instance associated with the "Customer" transaction, select the "ChangeSelectedCustomerStatus" action and set its "Row Selection Scope" property to "Only Visible Rows"
    Row Selection Scope

  2. Apply the pattern and generate the app.

Now see the change in the action's behaviour:

  1. Select some customers in the first page.
  2. Go to the second page, see how the action is not shown (because the action now applies to the current page and there are no selected rows)
  3. Select a customer.
  4. Apply the ChangeCustomerStatus action.
  5. See how the action is applied only to the current page.
  6. Return to the first page. See how the customers remains selected.
  7. Search for a customer that is not selected.
  8. See how the action is not shown.
  9. Select the customer.
  10. See that the action is applied only to that customer.

Note: You can disable row selection persistence by setting the "Persist Selected Rows" property in the "Work With" node to "False".

Persist Selected Rows

Tip: As multiple actions can act on a lot of records, you probably won't want it to be executed by accident! Using K2BTools, you can specify that an action must be confirmed by the user before it is executed. To do that, the developer must set the “Confirm” property to “True”. Try it out!