react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

Scroll to a row programmatically

Open sanjesh opened this issue 8 years ago • 6 comments

I am trying to implement scroll to a table row programmatically this library provides a way to do it through id's https://github.com/fisshy/react-scroll Is it possible to add id's to tbody and tr's and how do we make thead fixed and make only tbody scrollable?

sanjesh avatar May 29 '18 13:05 sanjesh

@sanjesh understand, right now I'm not consider to implement the scroll table, I need to recover all the functionalities from legacy react-bootstrap-table. After I done, I will implement it :)

Anyway, I will also spend some to to figure if we can apply https://github.com/fisshy/react-scroll, if it's easy to implement, I will add this feature ASAP. Actually, legacy react-bootstrap-table have scroll feature, but there're some unalign issues

AllenFang avatar May 31 '18 15:05 AllenFang

My requirements include

  1. Fixed table header with scrolling body (with fixed percentage of column widths) 2.Programmatically scroll to a row

I am facing alignment issues while trying to implement 1 and couldn't find a solution.

In this library http://issues.wenzhixin.net.cn/bootstrap-table/ thead, tbody and tfooter are implemented as 3 different tables. They might have done it to avoid this alignment issue. This would be a big change. Hope there is a better solution.

sanjesh avatar Jun 01 '18 13:06 sanjesh

@sanjesh I see, thanks your suggestion 👍

AllenFang avatar Jun 02 '18 05:06 AllenFang

  1. Fixed table header can be done with css, e.g.: .react-bootstrap-table { flex-grow: 1; overflow: auto; min-height: 2em; thead th { position: sticky; padding: 0.3em; top: 0; background: mix($primary, #eeeeee, 30); z-index: 10; outline: 1px solid #c8ced3;
    border:none; outline-offset: -1px; text-align: center; vertical-align: middle; } }

  2. for scrolling to specific row - you can add in column definition the id attribute: attrs: (cell, row) => ({id:rowid_${row.id}}),

this will output for specific column e.g.

then scroll with plain javascript: const rowId = 12 const el = document.getElementById('rowid_' + rowId) el.scrollIntoView();

with sticky header your row might be behind the sticky header (by browser what is considered into the view), then do something like: const tableEl = document.getElementsByClassName("react-bootstrap-table")[0] tableEl.scrollTop -= 50;

lindsejs avatar Dec 06 '18 13:12 lindsejs

For me this worked. // insert the new question in grid (async () => { arr_helpers.insert(insert_index, question_new); })().then(() => { this.prop.ref_questions[insert_index].scrollIntoView(); });

I am using Formik and its FieldArray component

hassanamjad91 avatar Jan 16 '20 14:01 hassanamjad91

Hello @AllenFang can anyone please suggest me how to scroll programmatically in table 2

lavania-aditya avatar Jun 29 '20 06:06 lavania-aditya