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 454 forks source link

How to refresh tableview with new set of updated data without losing the scrolled horizontal position #342

Closed ashish-d-hh closed 3 years ago

ashish-d-hh commented 3 years ago

I am looking for a way, where I update some value in the cell of a column, then I hit an API to save that change, and then reload data from API and then fill the table view again with it.

Currently what happens is if I am at column 30th, then on refreshing data I am taken back to 0th column

@evrencoskun

tableview.tableViewListener = clickListener
        tableview.setAdapter(mTableAdapter);
        tableview.setIgnoreSelectionColors(true);
        tableview.rowHeaderRecyclerView.setBackgroundColor(Color.BLACK)
        mTableAdapter?.setAllItems(
            mSelectedColumnHeaderList, mRowHeaderLotDetailsList,
            mCellList
        )
        mTableAdapter.notifyDataSetChanged()
ashish-d-hh commented 3 years ago

Solved it using following code:

private lateinit var preferencesHandler: PreferencesHandler
    private lateinit var preferencesOfPosition: Preferences

To save current position of scroll, use:

preferencesOfPosition= preferencesHandler.savePreferences()

To revert back to the save scroll, use

preferencesHandler.loadPreferences(preferencesOfPosition)

Thanks @evrencoskun for this great feature. 👍