Rails

Datatables - tables that you can search, sort, and paginate.
Gem Ransack is an great tool that I use in most of my apps to add search and sort.
Let's dive deep into how we can use Ransack!
At the end, we will also add pagination of our search results with gem Pagy.
When I was starting this channel, a "Ransack" video was one of my first ideas.
But ransack is a tool that has so many features, I just didn't know how to approach it in an easy-to-learn manner.
I hope you enjoy the example usecases I demonstrate in this screencast.
Episode source code: github.com/corsego/147-datata...
0:00 DataTables example
1:40 Ransack SORT
7:13 Ransack SEARCH
9:15 highlight search results
10:15 Date search fields
11:53 Select fields
13:45 One search field for many attributes
14:50 Search association
19:43 Ransack settings
22:08 Pagination with Pagy
24:20 Search, Sort and Pagination works!

Пікірлер: 20

  • @kalist8938
    @kalist893818 күн бұрын

    Omg super useful gems and video, thanks a lot !

  • @SupeRails

    @SupeRails

    11 күн бұрын

    Glad it was helpful!

  • @guymcdonald7961
    @guymcdonald7961Ай бұрын

    Love this. A great find! Subscribed 🎉

  • @alexax3888
    @alexax388826 күн бұрын

    This is great content as always! Thank you

  • @keilmillerjr9701
    @keilmillerjr97017 ай бұрын

    Thank you for these tutorials. I like that you make mistakes in the video, and then resolve them. It helps others learn how to diagnose errors.

  • @robbieclutton
    @robbieclutton4 ай бұрын

    Exactly what I was looking for, thank you.

  • @PROXYOWL
    @PROXYOWL7 ай бұрын

    thanks sir for the tutorial it was really helpful

  • @ricardomordaunt1101
    @ricardomordaunt11018 ай бұрын

    Thank you

  • @ledockol
    @ledockol8 ай бұрын

    Як завжди - чудовий і дуже корисний матеріал! Ярослав, ти майстер своєї справи! Дякую. Прим. Якби була трохи складніша розмітка, може б запхнув би цю таблицю (разом із сортуванням, фільтрацією) у турбо фрейм щоб оновлювати тільки її контент. Слава Україні!

  • @SupeRails

    @SupeRails

    8 ай бұрын

    turbo frames and complex markup problems? ok, in the next video!

  • @volodymyrshabaldas6349

    @volodymyrshabaldas6349

    8 ай бұрын

    yep, it will be a greate tutorial.@@SupeRails In my case, I already use ransak, pagy, turbo stream and frame in tables (like you did tutrorials before kzread.info/dash/bejne/c22lmLuwmK-pqaw.html) But I have issues with sort_link, when I take filtered data. By the way, thanks a lot, and plz. continue your greate work

  • @SupeRails

    @SupeRails

    8 ай бұрын

    @@volodymyrshabaldas6349 what kind of issues with sort link?

  • @volodymyrshabaldas6349

    @volodymyrshabaldas6349

    8 ай бұрын

    It display turbo request in UI (views), when I tried to press sort link after filtered data @@SupeRails

  • @ledockol

    @ledockol

    8 ай бұрын

    @@volodymyrshabaldas6349 If both turbo_request and turbo_stream are used within one action in the controller, it would be better to separate them to avoid complicating the logic of their interaction. In my opinion, it is better to have turbo_frame + broadcast or turbo_stream + broadcast. Although there are exceptions in real projects)

  • @SupeRails
    @SupeRails8 ай бұрын

    Gem Ransack: github.com/activerecord-hackery/ransack

  • @YuriyChamkoriyski
    @YuriyChamkoriyski6 ай бұрын

    Thanks, Yaroslav! Your videos are always interesting and useful! I have one question, though. When you do the sort, the gem makes it very easy, and when you click on the column's title it sorts the column right away. My question is, once I load the page how can I have some kind of default sorting already executed, without clicking on any particular column's title? So, the table should have some initial sort (let's say by first_name: DSC) and then the user could change it by clicking on the different column's title.

  • @SupeRails

    @SupeRails

    6 ай бұрын

    if you are using ransack, the best way to set default sort order is with "@q.sorts". Example: @q = Event.where(visible: true).ransack(params[:q]) @q.sorts = "name asc" if @q.sorts.empty? @events = @q.result(distinct: true)

  • @SupeRails

    @SupeRails

    6 ай бұрын

    without ransack: @events = Event.all.order(created_at: :desc)

  • @developerfoe
    @developerfoe8 ай бұрын

    there is rsome issue of ransack with rails 7.1 , don't know how much time will it take to be compatible with rails 7.1

  • @SupeRails

    @SupeRails

    8 ай бұрын

    actually for this tutorial I am using rails 7.1 - seems to work!