caduandrade / davi_flutter

A full customized data view that builds the cells on demand. Focused on Web/Desktop Applications. Bidirectional scroll bars.
MIT License
55 stars 18 forks source link

programmatically jump/scroll to a specific row #94

Open Haugpro opened 1 month ago

Haugpro commented 1 month ago

is there a way to jump or scroll to a specific row programmatically? This is a must have feature for a planned desktop app. Comparing some datagrids for flutter, davi fits best by now, except of this feature. Maybe I have not seen it

caduandrade commented 1 month ago

Hi @Haugpro !

I'm traveling on vacation, when I get back I'll see this better but I believe you can pass your own ScrollController and use it then you should be able to use jump normally. Isn't this the case reported in #93?

Haugpro commented 1 month ago

thanks for this quick answer. Did not want to disturb you on your vacation. You are right, it's the same question as #93, did not look close enough. I'm not sure I have enough flutter experience to replace/overwrite the scroll controller, but I will try

Haugpro commented 1 month ago

I roughly followed the recipe from MHscorpion (issue #93) and it seems to work. To jump to a specific row index instead of a percentage position I added this function:

void jumpToRowIndex(int index) { if ((rows.length > 1) && !index.isNegative && (index < rows.length)) { // because 0 length is dangerous and 1 is useless _extraVerticalScrollController!.jumpTo(_extraVerticalScrollController!.position.maxScrollExtent / (rows.length - 1) * index); } }

NOTE that this assumes that all rows share the same height !!