SortTable getActualRowAt

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

SortTable getActualRowAt

Postby paulpablo » Mon Mar 24, 2008 11:55 am

I see that I need to translate the index in SortableTable to the index in my model using the getActualRowAt method. That makes sense.

It would be convenient to have a 'getActualSelectedRows' method in SortTable. I've been extending SortTable and adding the following. Is there a possibility of adding something like this in a future release?

public int[] getActualSelectedRows(){
int rows[] = getSelectedRows();
int actualRows[]=new int[rows.length];
for (int i =0; i<rows.length; i++){
actualRows[i]=getActualRowAt(rows[i]);
}
return actualRows;
}
thanks
paulpablo
 
Posts: 21
Joined: Mon Nov 12, 2007 1:17 pm

Postby JIDE Support » Mon Mar 24, 2008 12:42 pm

Actually, the correct way is to use TableModelWrapperUtils.getActualRowAt method. The getActualRowAt on SortableTableMode will only work if there is one TableModelWrapper. If you use several TableModelWrappers such as SortableTableModel, FilterableTableModel, TableModelWrapperUtils.getActualRowAt is the right way to get the actual row index as in your original table model.

The convenient is nice but I would probably rather add it to TableModelWrapperUtils so that it works for all TableModelWrapper cases such as for FilterableTableModel.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby paulpablo » Tue Mar 25, 2008 1:02 pm

Ok, I think I understand. So it should be more like

[code]
public static int[] getActualRows(TableModel tableModelWrapper, int rows[]){
int actualRows[] = new int[rows.length];
for (int i=0; i<actualRows.length; i++){
actualRows[i]=TableModelWrapperUtils.getActualRowAt(tableModelWrapper, rows[i]);
}
return actualRows;
}
[/code]

And then I would call it with something like:

int rows[]=getActualRows( tableModelWrapper, table.getSelectedRows());
paulpablo
 
Posts: 21
Joined: Mon Nov 12, 2007 1:17 pm

Postby JIDE Support » Tue Mar 25, 2008 1:05 pm

We actually coded it already and it will be in next release.

Code: Select all
    /**
     * Gets the actual rows based on the row indices of the outermost TableModel. This method can be
     * used in combination with table.getSelectedRows() which returns an int array to find out the
     * actual row indices in the actual table model.
     *
     * @param outerModel the outermost TableModel.
     * @param rowIndices the row index array of outermost TableModel
     * @param sort       true to sort the returned row indices. If false, the order will be the same
     *                   as the order of the rowIndices parameter.
     *
     * @return the row index array of nested model which is not a table wrapper.
     */
    public static int[] getActualRowsAt(TableModel outerModel, int[] rowIndices, boolean sort) {
        List<Integer> actualRows = new ArrayList();
        for (int row : rowIndices) {
            int actualRow = getActualRowAt(outerModel, row);
            if (actualRow != -1) {
                actualRows.add(actualRow);
            }
        }
        int[] indices = new int[actualRows.size()];
        for (int i = 0; i < actualRows.size(); i++) {
            int row = actualRows.get(i);
            indices[i] = row;
        }
        if (sort) Arrays.sort(indices);
        return indices;
    }
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby paulpablo » Tue Mar 25, 2008 1:07 pm

Great, thanks!
paulpablo
 
Posts: 21
Joined: Mon Nov 12, 2007 1:17 pm

Postby JIDE Support » Mon Apr 07, 2008 9:15 pm

Just so you know, the fix is included in 2.2.3 we just released.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby djdj » Sun Jun 01, 2008 11:49 am

Hi,

In order to get the row index of my outer model I'm calling:
TableModelWrapperUtils.getRowAt(outerTableModel, filterableTableModel, selectedRow);

But I still having the row index in inner model.

Please, can you help me to figure out where is the problem?
djdj
 
Posts: 4
Joined: Sun Jun 01, 2008 11:38 am

Postby JIDE Support » Sun Jun 01, 2008 3:15 pm

The filterableTableModel parameter should be the actual table model. You probably can get it using filterableTableModel#getActualModel.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby djdj » Mon Jun 02, 2008 8:21 am

Hi,

Thanks for your reply.

After profiling my demo, I make it working calling :
TableModelWrapperUtils.getActualRowAt(filterField.getDisplayTableModel(), selectedRow));

Where filterField = new QuickTableFilterField();

Thanks
djdj
 
Posts: 4
Joined: Sun Jun 01, 2008 11:38 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 10 guests

cron