DataGrid: How to filter displayed rows?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

DataGrid: How to filter displayed rows?

Post by sritcp » Mon Jun 09, 2014 5:13 pm

I have my master data table in a DataGrid on the main card.
On each of the subsequent cards, I need to display a different subset of this information: selected rows (records) and selected columns.
I don't want to create different DataGrids (because I need "edit anywhere, update everywhere"), but use the same DataGrid displayed differently on different cards.

I see that it is easy to select a subset of columns: simply
set the dgProp["columns"] of group myDataGrid to myColumnSubset
I don't see a corresponding simple way to filter the rows displayed.
The rows can be filtered, for example, by a value (or values) in a column.

I have waded through the manual, and searched this forum (due diligence :D ), but no luck.
Any ideas?

As an aside, we need to create a sub-board for DataGrid and move all the relevant messages there! It is a complicated subject.

Thanks,
Sri.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10335
Joined: Wed May 06, 2009 2:28 pm

Re: DataGrid: How to filter displayed rows?

Post by dunbarx » Mon Jun 09, 2014 6:17 pm

Hi.

Love your idea about a separate DG board.

Standard disclaimer: "I use DG's, but barely understand them"

Access to rows is more limited than the built-in access to columns. It derives from the record paradigm that these are built upon. If there is no "native" method (and there might be) I would extract the dgText from the master DG, and use standard techniques to populate the child DG's. You can set this up with a single function placed high in the message path for any work you need to do. Just set up parameters for each child.

Craig Newman

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: DataGrid: How to filter displayed rows?

Post by sritcp » Mon Jun 09, 2014 7:36 pm

Hi Craig:

1. I agree that one could go the dgText route, but the central problem doesn't go away. If you have a child DGs (as opposed to a single DG displayed differently on each card), any edit to a child DG has to be broadcast to the parent (master data) DG as well as other child DGs that may contain the record.

2. An alternative is to create a unique selector column for each card and assign 1 or 0 to each row. Now, by sorting that column, we can make the relevant rows appear at the top of the table. For good measure, we can color the non-relevant rows. Not an elegant solution, but may just do the job.

3. Ultimately, I think the solution is in modifying FillinData command to skip certain records. This is above my pay grade! May be someone will post a handy code snippet.

4. I think DataGrid is great. What it needs is a graphical developer interface where we can set the switches visually.

Regards,
Sri.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: DataGrid: How to filter displayed rows?

Post by bangkok » Mon Jun 09, 2014 11:00 pm

sritcp wrote:1. I agree that one could go the dgText route, but the central problem doesn't go away. If you have a child DGs (as opposed to a single DG displayed differently on each card), any edit to a child DG has to be broadcast to the parent (master data) DG as well as other child DGs that may contain the record.
This is a requirement you didn't specify in your first message. :)

In any case, you could use a "unique ID" for each row in the master dataset. Then, If a row is modified within a sub dataset, you could copy the modification thank to this ID, into the master dataset.
sritcp wrote: 2. An alternative is to create a unique selector column for each card and assign 1 or 0 to each row. Now, by sorting that column, we can make the relevant rows appear at the top of the table. For good measure, we can color the non-relevant rows. Not an elegant solution, but may just do the job.
This is a rather complicated solution.

Like Craig said, i would rather go for "brute force" :

-keep your master dataset in a variable
-apply all the filters you want on a copy of this variable
-inject the content of this new variable into a datagrid
-by adding the idea of a unique ID for each row you can keep a trace of any modification made in a sub datased and copy it into the master dataset

Last but not least... you could go... the "SQL way".

Store your data in a SQLLite file. And all your problems will be solved : you can filter, search, update, insert, and simply display your in a single datagrid.

Because eventually what you describe, is nothing more -and nothing less- than a database. :D

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: DataGrid: How to filter displayed rows?

Post by sritcp » Tue Jun 10, 2014 1:20 am

Hi Bangkok:
bangkok wrote:This is a requirement you didn't specify in your first message. :)
Well, I did, using different words, as below :D :
....I don't want to create different DataGrids (because I need "edit anywhere, update everywhere"), but use the same DataGrid displayed differently on different cards.....
bangkok wrote:In any case, you could use a "unique ID" for each row in the master dataset.
Yes, this is exactly what I have done.I have added column called "idNum". If a row in a child DG was updated, I'll need to copy the dgText of the Master DG, change the values and reset the dgText -- every time! With a single DG, it is simpler. Or so I thought.
bangkok wrote:... the "SQL way".
I guess you are right. Time to start learning SQLite.

Thanks for your help,
Sri.

Post Reply