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

Columns get unhidden on table filtering #316

Open Parlae opened 4 years ago

Parlae commented 4 years ago

I have several columns in a table hidden, because I want to include their contents when performing a search but otherwise they don't need to be visible. The problem is when I do the search all columns get shown, and when I try to hide them again I got index out of bounds exception. I tried then to firstly show all the columns and clear hidden column list, end it gave inconsistent results (hiding column headers but showing complete rows etc)

private void searchTable(String searchString) {

       mTablePortraitViewFilter.set(searchString);

       try {
           mTablePortretView.showAllHiddenColumns();
           mTablePortretView.clearHiddenColumnList();
           hideTrivialColumns();
       } catch (Exception e){
           e.printStackTrace();
       }
}
private void hideTrivialColumns() {
        mTablePortretView.hideColumn(8);
        mTablePortretView.hideColumn(10);
        mTablePortretView.hideColumn(11);
        mTablePortretView.hideColumn(12);
        mTablePortretView.hideColumn(13);
        mTablePortretView.hideColumn(14);
        mTablePortretView.hideColumn(0);
    }

How can I prevent hidden columns from showing when filtering?

Thanks in advance

Parlae commented 4 years ago

To be precise, problem occurs when I start deleting characters in search field and all rows are getting shown back. This is the exception I get:

java.lang.IndexOutOfBoundsException: Index: 9, Size: 8
at java.util.ArrayList.remove(ArrayList.java:503)
at com.evrencoskun.tableview.adapter.recyclerview.AbstractRecyclerViewAdapter.deleteItem(AbstractRecyclerViewAdapter.java:92)
at com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter.removeColumnItems(CellRecyclerViewAdapter.java:237)
at com.evrencoskun.tableview.adapter.AbstractTableAdapter.removeColumn(AbstractTableAdapter.java:293)
at com.evrencoskun.tableview.handler.VisibilityHandler.hideColumn(VisibilityHandler.java:108)
at com.evrencoskun.tableview.TableView.hideColumn(TableView.java:563)
at com.example.parlae.workMobileAndroidX.Fragments.ReservationsListFragment.hideTrivialColumns(ReservationsListFragment.java:559)
at com.example.parlae.workMobileAndroidX.Fragments.ReservationsListFragment.searchTable(ReservationsListFragment.java:340)
at com.example.parlae.workMobileAndroidX.Fragments.ReservationsListFragment.access$200(ReservationsListFragment.java:67)
at com.example.parlae.workMobileAndroidX.Fragments.ReservationsListFragment$2.onTextChanged(ReservationsListFragment.java:194)
at android.widget.TextView.sendOnTextChanged(TextView.java:9364)
at android.widget.TextView.setText(TextView.java:5397)
at android.widget.TextView.setText(TextView.java:5250)
at android.widget.EditText.setText(EditText.java:113)
at android.widget.TextView.setText(TextView.java:5207)
at com.example.parlae.workMobileAndroidX.Fragments.ReservationsListFragment$3.onClick(ReservationsListFragment.java:210)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)     
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)    
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)D/TurnoverDetailsFragment: onTextChanged: fff
E/ColumnLayoutManager: x: 11 y: 0 fitWidthSize right side
indieshack commented 4 years ago

Ditto - I'm in exactly the same position - hidden columns become visible on filtering - any workarounds?

Parlae commented 4 years ago

@indieshack Hi, I placed two table views, one with fewer columns in portrait orientation, and one for landscape orientation with all the columns, but its a poor workaround.

indieshack commented 4 years ago

@Parlae thanks - I spent hours last night trying to track down the issue in the pagination/filtering code with no luck. Additionally, after filtering, a select on the filtered data and a call to get the data in a selected row, i.e.

mTableView.getAdapter().getCellItem(0, mTableView.getSelectedRow())).getContent()

returns incorrect data because it's pulling the data from the original data array

Parlae commented 4 years ago

Additionally, after filtering, a select on the filtered data and a call to get the data in a selected row, i.e.

mTableView.getAdapter().getCellItem(0, mTableView.getSelectedRow())).getContent()

returns incorrect data because it's pulling the data from the original data array

Yes, I noticed that as well. What you can do is add a column with row numbers and then reference data by using row number as the index of the data array

PallaviSiddabathula commented 3 years ago

I have the same issue. Can you please rectify this.