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

search #136

Open farzadkamali20 opened 6 years ago

farzadkamali20 commented 6 years ago

hi friend. how I can search in tableview. i don't want filter, i want select row that I searched. for example I want find 111 in column id that it is unique, and set selected row. i dont know row number 111 that use this code:

tableView.setSelectedRow(row);

how to find that.

evrencoskun commented 6 years ago

Hi @farzadkamali20,

If you try to find a cell item that whose id is "111", you can do this.


          int row =  findRowById("111");
          if(row != -1){
              tableView. setSelectedRow(row);
          }

          private int findRowById(String id){
        List<List<Cell>> mCellItems = tableViewAdapter. getCellRecyclerViewAdapter(). getItems();

        for (int i = 0; i < mCellItems.size(); i++) {
            List<Cell> row = mCellItems.get(i);

            for (int j = 0; j < insertRowData.length; j++) {
                Cell item = row.get(j)
                if(item.getId().equals(id)){
                    return i;
                }
            }
        }

        return -1;
    }