Reece Jones

Joined

430 Experience
4 Lessons Completed
0 Questions Solved

Activity

that will display the items in reverse, sure. But it is not quite what I'm meaning.

Let's say I drag and drop the first div to the second div. The event will still contain the following:

newIndex: 1
oldIndex: 0

what I want it to be:

newIndex: 2
oldIndex: 3

Is there anyway to reverse the index and position order? For example:

<div>First div</div> <%# index: 3, position: 3 %>
<div>Second div</div> <%# index: 2, position: 2 %>
<div>Third div</div> <%# index: 1, position: 1 %>
<div>Fourth</div> <%# index: 0, position: 0 %>

This way it appears and is applied in descending order instead of ascending

Posted in Datatables From Scratch Using Hotwire Discussion

Say I wanted to add multiple separate search scopes instead of just one. For example

@employees = @employees.search(params[:query]) if params[:query].present?
@employees = @employees.start_date(params[:start_date]) if params[:start_date].present?
@employees = @employees.created_at(params[:created_at]) if params[:created_at].present?
...

How could I simplify and clean up this logic? Is there a way to iterate through these?

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.