LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reoder array of cluster by date

Hello guys,

 

I have this cluster array, I would like to redefine it with the following rules:

 

Sort by longest duedate date (from closest to farthest)
After appearing the items that duedate are empty

 

If possible:
Reorder the empties duedate from oldest to newest by sorting by created

 

leandrofeder_0-1742315806600.png

 

Could you help me?

0 Kudos
Message 1 of 9
(397 Views)

snip.png

 Sorts by duedate, You can do the same kind of sort for the date created.

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 2 of 9
(369 Views)

That's a great solution. 

 

The first loop could also detect the empty due dates and then create a second array of data from the date created to be then sorted out on another stage.

0 Kudos
Message 3 of 9
(355 Views)

Jay's solution obviously works but for a touch more explanation, the "Sort" function can sort clusters directly. It just sorts it by the first element. You would need to reorder the controls in your cluster.

 

Also, depending on your use case, you can look at a couple options. The first is to use a database to handle this, which you could query with simple commands. I'd recommend SQLite which is a single file you can interact with.

 

Also, if you replace the cluster with objects, you can specify your own "Greater than" operator for the class and use "Sort 1D array.vim":

 

BertMcMahan_0-1742321545497.png

 

You'd need to replace your string date/time controls with timestamps for the best "sortability" IMHO. Just depends on what exactly you're trying to accomplish long term.

Message 4 of 9
(354 Views)

When I get to the items where the due date is empty, it's copying the last row that had due date and copying it to the rest of the rows

 

leandrofeder_0-1742322565535.png

leandrofeder_0-1742322610100.png

 

0 Kudos
Message 5 of 9
(349 Views)

Hi Leandro,

 

why don't you sort the cluster array right after the first FOR loop?

What's the point of sorting the timestamp array and searching for items in this array, just to pick other elements in your cluster array!?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 9
(328 Views)

@leandrofeder wrote:

When I get to the items where the due date is empty, it's copying the last row that had due date and copying it to the rest of the rows

 

 


 The find in array finds the first instance, you need to do a nested sort on all the blank duedates and sort them by date created. Also in your example the timestamps are unique which makes the find in array work. If the timestamps are not unique, you get the issue you noted and will have to figure out soemthing clever to handle that case : ) 

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 7 of 9
(319 Views)

@BertMcMahan wrote:

Jay's solution obviously works but for a touch more explanation, the "Sort" function can sort clusters directly. It just sorts it by the first element. You would need to reorder the controls in your cluster.

 

Also, depending on your use case, you can look at a couple options. The first is to use a database to handle this, which you could query with simple commands. I'd recommend SQLite which is a single file you can interact with.

 

Also, if you replace the cluster with objects, you can specify your own "Greater than" operator for the class and use "Sort 1D array.vim":

 

BertMcMahan_0-1742321545497.png

 

You'd need to replace your string date/time controls with timestamps for the best "sortability" IMHO. Just depends on what exactly you're trying to accomplish long term.


You can define a custom comparison without using objects. The VIM takes static VI reference too.

avogadro5_0-1742346852356.png

avogadro5_1-1742346877199.png

 

 

Message 8 of 9
(294 Views)

@avogadro5 wrote:


You can define a custom comparison without using objects. The VIM takes static VI reference too.

 


Did not know that, thanks!

0 Kudos
Message 9 of 9
(223 Views)