evrencoskun / TableView

TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
MIT License
3.14k stars 459 forks source link

select row #269

Open 10erlosh opened 4 years ago

10erlosh commented 4 years ago

Hi,

thanks for this great library! Is there a sane way to select the whole row onCellClicked and onRowHeaderClicked?

MGaetan89 commented 4 years ago

Did you try TableView#setSelectedRow(int)?

10erlosh commented 4 years ago

@MGaetan89 yes, i did. It works fine but now i have another problem:

when performing sorting via onColumnHeaderClicked the previously selected row gets un-highlighted and the column gets highlighted. How can this be prevented?

@Override
public void onColumnHeaderClicked(@NonNull RecyclerView.ViewHolder viewHolder, int column) {
    tableView.setIgnoreSelectionColors(true); //experimental
    tableView.sortColumn(column, tableView.getSortingStatus(column) == SortState.ASCENDING ? SortState.DESCENDING : SortState.ASCENDING);
    adapter.getColumnHeaderRecyclerViewAdapter().notifyDataSetChanged();
    tableView.setIgnoreSelectionColors(false); //experimental
}
evrencoskun commented 4 years ago

Hi @10erlosh,

As far as I understand from your question, you want to unselect the selected rows after sorting process.

You can clear selection using the below line before sorting process; tableView.getSelectionHandler().clearSelection()

After that, you can also select any of row using this; tableView.setSelectedRow(row)

By the way, do these code snippets work?