Hi All,

Is it possible to have a Item (combobox) in a DataGrid which keeps track of the number of rows selected. The Datagrid has an extra column (combobox) that can be check by the user. I need to find a method to count the number of rows selected by the user by checking the combobox column. I can't use the api_datasource as this column is not a datasource column.



asked 29 May '13, 08:04

suranga's gravatar image

accept rate: 0%

Hi Suranga,

I see. In this case, you still need to hook the CheckBox to a Datasource Columns. No problems though, This is a common thing to do in Formspider. Here are the steps I followed:

1- Create a new application which points to the HR schema 2- Create a Datasource Definition based on the following Query:


3- Uncheck the Updateable Checkbox for the Checked_YN column in the Columns tab of the Datasource Definition Dialog. This is to ensure that the Checked_YN column is not included in the DML statements.

4- Update the mainPanel with the following XML code:

      <cell hAlign="Full" vAlign="Full">
        <grid name="Grid1" selectionType="SelectOne" dataSource="DEPARTMENTS1">
            <selectionChanged action="doSelectionCount"/>
          <column headerLabel="Department Name">
            <textField column="DEPARTMENT_NAME"/>
          <column headerLabel="Selection">
            <checkBox column="CHECKED_YN">
                <valueChanged action="doSelectionCount2"></valueChanged> 
      <cell hAlign="Full">
        <textLabel label="Number of Selected Rows:"/>
        <textField value="0" name="countIndicator" editable="N"/>

5- Create the action references in the XML above which points to the following PL/SQL procedure:

procedure doSelectionCount2 is
  v_count_nr number;
  v_datasourceQuery_tx varchar2(32000);
  v_countQuery_tx varchar2(32000);
  v_countQuery_tx:='select count(*) from ('||v_datasourceQuery_tx||') where checked_yn=''Y''';
  execute immediate v_countQuery_tx into v_count_nr;

There are multiple ways to count the ticked CheckBoxes. I find the method above the most convenient. We simply get the SQL which returns the entire row set in the datasource and add a where clause to it to only count the ones we are interested in.

Hope this helps.

Kind Regards, Yalim


answered 29 May '13, 09:39

Yalim's gravatar image

Yalim ♦♦
accept rate: 23%

Hi Suranga,

I am not sure if I understood the question 100% but is this what you meant?

I built a small sample application that has a Grid and a textBox which shows the number of selected rows in the Grid. I used the Departments table in Oracle supplied HR schema. Here are the steps I followed

  1. Create a new application which points to the HR schema
  2. Create a Datasource Definition based on the Departments table
  3. Update the mainPanel of the application with the following XML:

    <panel> <tablelayout> <row> <cell halign="Full" valign="Full"> <grid name="Grid1" selectiontype="SelectMultiple" datasource="DEPARTMENTS1"> <events> <selectionchanged action="doSelectionCount"/> </events> <column headerlabel="Department Name"> <textfield column="DEPARTMENT_NAME"/> </column> </grid> </cell> </row> <row> <cell halign="Full"> <textlabel label="Number of Selected Rows:"/> </cell> <cell> <textfield value="1" name="countIndicator" editable="N"/> </cell> </row> </tablelayout> </panel>

4- Create the action references in the XML above which points to the following PL/SQL procedure

procedure doSelectionCount is
  v_selectedRowIDs_t api_component.tt_selectedrows;

Run the app. Note that the number showed in the countIndicator textField increases and decreases depending on the number of rows you select in the Grid.

Is this what you had in mind?

Kind Regards, Yalim


answered 29 May '13, 08:39

Yalim's gravatar image

Yalim ♦♦
accept rate: 23%

edited 29 May '13, 08:45

Hello Yalim,

Thank you for the answer. It's almost what i expected. Let's assume that there is checkbox column in the Gird that allows the user to select given rows. This column has no relation with the datasource. Is it possible to obtain the selected rows (number of rows) via the checkbox?



(29 May '13, 09:07) suranga
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 29 May '13, 08:04

Seen: 1,879 times

Last updated: 29 May '13, 09:39

© Copyright Gerger 2017