Listview sorting by main text

I have a ToDo list with listview.

No I want to sort the listview entries simply using main text.

I can sort by date using index 3, date is detail text, this is working. Listview layout is vertical with maintext and detailtext.

Sorting main text with index 1 or 2 is not successful.

I store the main and detail text by list, i guess there is some index missing in the list of lists.

How can i sort listview by main text?


ListView Sorting sample run
listview_sorting.aia (1.2 MB)

Image file names:

1 Like

(added to FAQ)

1 Like

Thank you ABG, i try the using key called block.

I also want to store the listview with TinyDB, but the listview is empty after initialize screen1 ?

Without using extensions.

ListView Elements have a secret proprietary structure, subject to arbitrary change as the ListView evolves.

So it's not a good idea to try to save them directly to Tinydb.

However, that doesn't stop us from writing value procedures to swap in plain old three column tables for storage and retrieval in data bases.

I prefer to use local variables for editing things that live in tinydb, to avoid doubt about who is in charge (tinydb or the global variable)

There's also the issue of the side effects of the ListView AddElement block. Does it do an insert to the component Elements? Are we interfering with that?

I am AFK for several hours if you want to experiment.

Here's half of what you will need ...

(draggable procedure)

the draggable procedure is very helpful

Here's the rest of it, in my sample app:

I added 2 buttons for saving and loading to TinyDB.



global ListView1TAG
listview_sorting.aia (1.2 MB)


1 Like

I cannot find this blocks of your .aia in listview blocks

grafik

grafik

Where are they from?

Those are Generic blocks.

You can get them in any of three ways:

  • Under the Any branch of the Blocks Pallette (below the component blocks)
  • Take a ListView block, right click on it, select Make Generic, and replace the component value
  • Typeblock "ListView.Elements"

i want to add items to the list using insert to add items to the top of list, save it, and load them with tinydb.

something seems missing when saving to tinytb.

grafik

the use of the variable listekurza is a little bit confusing:

  • is defined as a list of dictionaries
  • is used as if it were a dictonary ( and with its default value )
  • in screen1.initialize is defined as a list of strings

You are also reading two tags from tinydb ( maintext, detailtext ) which you have not stored ( at least in the blocks posted )

I tried this, load is working temporarily, but not after restart the app

You ignored the dictionary list parameter

Here's the mistake behind the mistake...

Never use a global variable in a procedure.

Here is my approach, one that I always take when working with data in a listview: maintain a masterlist, and use this to generate a listview list when required, never actually working directly with the listview list - this is just for display.

A simple example:

I will go further..

Once you commit to storing the data in Tinydb, you must regard that global variable as an evil twin, or a pretender to the throne

You must eliminate it with extreme prejudice.

Everywhere.

Great, It works with the masterlist and a separate listview list, that means storing listview data is also possible without using a dictionary?

You store the data in a list, you display the data in a listview. Don't confuse the two.

You could store your data as a list of lists instead of a list of dictionaries.

The difference is, with a list, you have to remember which item number is the master text and which is the detail text.

ith a dictionary, you have to remember the exact spelling of the keys in the dictionary that holds the two texts, master and detail.

It's possible to screw up both equally, if you don't place close attention.