Setting focus to a Data Grid

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

fritzdekatt
Posts: 57
Joined: Fri Feb 09, 2018 2:28 am

Re: Setting focus to a Data Grid

Post by fritzdekatt » Thu Nov 14, 2019 11:30 am

dunbarx wrote:
Wed Nov 13, 2019 5:16 pm
Richard suggests table fields. I like table fields.

But you have to massage a new table field before it is stable. See this:
viewtopic.php?f=7&t=31452&p=170731&hili ... ly#p170731

Once properly set up, these fields are very easy to use.

Craig
Richard

I'm going to address all related comments here regarding the table field. I did view the linked posts and the video and I saw Craig's fix for the problem described (and I could implement it, but it might be unsustainable for someone at my level of skill with LC, since I don't really know what's happening with it).

I would love to use a table field (or anything) rather than a datagrid for sure. It looks more like a simple spreadsheet and is way easier to handle as an object (no copy problems, attached templates, etc). But selecting and editing a table field via the keyboard seems just as problematic as the data grid. Once you click on it you're fine, but adding rows and getting to the next row and doing column totals and such seem like quite a task. I don't see the documentation on this.

A gentleman troubled himself to do a prettified table field template which I borrowed, but you still can't do headers, which kind of negates its use as a spreadsheet. I suppose you could put them at the top of a loop like you do in php when reading a database table, but that seems tailored to bite you in the posterior down the road when you're trying to do column totals and refreshes.

Bottom line, I'd be glad to return to this option if someone could point me to documentation I haven't seen yet. The main deficit I see so far is that a "column" in a table field is really just a tab and in the data grid at least it seems to be an object, and a field (thanks to Michael Bluejay) can be addressed as row instance of a column.

FYI: I'm on Mac Sierra using Community Plus 9.01 and Commercial 5.5, and I've noticed the weird table field text placement also when adding data manually for test purposes, though it seems fine when I dump SQL into it.

Thank all of you for your input as always,
fritz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9626
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting focus to a Data Grid

Post by dunbarx » Thu Nov 14, 2019 6:50 pm

Hi.

If you want headers and such, you are probably going to have to use a DG. I have one comment. Since I am lazy, I try to stay out of the DG API as much as possible. I do this by extracting the entire contents of the DG with either the dgText or the dgData, do all my massaging back in good ol' LC, and then restoring. This seems like a little more work, and it is, but fits my comfort level.

Craig

fritzdekatt
Posts: 57
Joined: Fri Feb 09, 2018 2:28 am

Re: Setting focus to a Data Grid

Post by fritzdekatt » Thu Nov 14, 2019 7:57 pm

dunbarx wrote:
Thu Nov 14, 2019 6:50 pm
Hi.

If you want headers and such, you are probably going to have to use a DG. I have one comment. Since I am lazy, I try to stay out of the DG API as much as possible. I do this by extracting the entire contents of the DG with either the dgText or the dgData, do all my massaging back in good ol' LC, and then restoring. This seems like a little more work, and it is, but fits my comfort level.

Craig
Of necessity, I'm doing that now. I don't do much massaging in LC, but handle refreshes and formatting in SQL. I have to think that if I was doing all that externally anyway, I'd be better off with a table field. Even though I can't define a column, I can reference a row and tab location and get "field" data out of it. All the bells and whistles like sorting I can do through SQL. The header thing is the big conundrum, but only if I use the list (whether data grid or table field) as a spreadsheet-like editor. Rather than mess with the row templates to add dropdowns and such (which look prosaic in LC, in my opinion, and seriously lack cosmetic configurability options), I'd just as well handle that with form fields.

Still, I'd like to be able to select and enter the table field via the keyboard. Why do they make just selecting a field so difficult? Or am I missing something?

Thanks
fritz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9626
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting focus to a Data Grid

Post by dunbarx » Thu Nov 14, 2019 9:34 pm

Still, I'd like to be able to select and enter the table field via the keyboard.
Do you mean do this, in a button script:

Code: Select all

on mouseUp
   click at "118,228"
end mouseUp
This will open the phantom field, and you can start typing right away.

This issue is knowing where to click. A table field can respond to something like this:

Code: Select all

on mouseUp
   set the itemDel to tab
   select item 2 of line 2 of fld 2
end mouseUp
But that only selects an item in the field; typing is ignored. In other words, without the phantom, the main functionality is lost. Now this can easily be scripted, in that LC can know where each "cell" is by knowing the topLeft of the table field, the tabStops, and the lineHeight. Simple, but does it sound like fun?

It does to me :wink:

Craig

fritzdekatt
Posts: 57
Joined: Fri Feb 09, 2018 2:28 am

Re: Setting focus to a Data Grid

Post by fritzdekatt » Thu Nov 14, 2019 10:26 pm

dunbarx wrote:
Thu Nov 14, 2019 9:34 pm
Still, I'd like to be able to select and enter the table field via the keyboard.
Do you mean do this, in a button script:

Code: Select all

on mouseUp
   click at "118,228"
end mouseUp
This will open the phantom field, and you can start typing right away.

This issue is knowing where to click. A table field can respond to something like this:

Code: Select all

on mouseUp
   set the itemDel to tab
   select item 2 of line 2 of fld 2
end mouseUp
But that only selects an item in the field; typing is ignored. In other words, without the phantom, the main functionality is lost. Now this can easily be scripted, in that LC can know where each "cell" is by knowing the topLeft of the table field, the tabStops, and the lineHeight. Simple, but does it sound like fun?

It does to me :wink:

Craig
Craig

Both of these bits of code certainly work well. The first, as you say, is more immediately useful to me but the second is a great way to get data out of a "cell".

From a purist standpoint, one wonders why assigning the focus to any object would not be standardized, but I'll take these two methods with pleasure. I'm going to assume I'd have trouble with this (the first method) if I had the field attached the bottom of a sizable form, but i'll cross that bridge when I come to it. If I resize rather than move I should be okay.

The data grid is (or can be) such a pain I'm almost ready to dump it for this project. I can get data in and out of the datagrid, and I only use the table field for holding a sql select, so I have to try to write back to a database table with the field.

I am assuming I understand your "phantom field" reference by reading other posts on this forum relating to the table field (some of which involve you). This seems to relate to the visual artifact I have also noticed when manually populating a table field. These references are one of the main reasons I've been sticking with the data grid. This anomaly seems almost intrinsic to the problem of refreshing the contents of a field with flexible or arbitrary tab delimiters, kind of like refreshing a page layout in InDesign when you're moving it at the same time. It's telling that you're restating what I consider a field property (set item delimiter) in the mouseUp code after the object has been drawn.

I will let you know how this works out.
Bigtime thanks for the tips.
fritz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9626
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting focus to a Data Grid

Post by dunbarx » Thu Nov 14, 2019 10:49 pm

So I am having fun.

But how would you, given a populated table field, select a "cell"?

Once inside, tabbing (and shift-tab) moves left and right, return works, and the arrowKeys do their job. But how would you just love to select a cell from the outside via the keyboard? Surely not finding a piece of text?

Cant have fun until I know the answer...

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9626
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting focus to a Data Grid

Post by dunbarx » Thu Nov 14, 2019 10:53 pm

Just saw your latest post, which crossed mine in the mail.

A table field is just a field. But it contains the ability to create and overlay an ephemeral editable field that is sized and located dynamically on top of the "cell" where one clicks. Once its job is done, it populates the underlying cell with its contents, and then vanishes. It is a kluge, but a nice one.

Is the ephemeral field your "visual artifact?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9626
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting focus to a Data Grid

Post by dunbarx » Thu Nov 14, 2019 11:11 pm

Fritz.
The main deficit I see so far is that a "column" in a table field is really just a tab and in the data grid at least it seems to be an object, and a field (thanks to Michael Bluejay) can be addressed as row instance of a column.
I want to make sure that there are not overlapping issues here. When I said I was lazy, i meant it. If I extract the contents of either a table field or a DG, I end up with a tab and return delimited dataSet. From there it is straightforward to isolate, say, column 2, since I only need to set the itemDel to tab and loop through all the lines, pulling out item 2 in each. This is a few lines of code, but instantaneous in execution, especially with "repeat for each...".

But if you are doing all that yourself anyway, why do you need headers? Is that an interface feature for your users?
restating what I consider a field property (set item delimiter)
The itemDelimiter is a property that is valid for any container: variables, URLs, fields, buttons, and images. It is one of the most powerful and useful of any native gadget in LC. Love it. You cannot parse without it.

Craig

fritzdekatt
Posts: 57
Joined: Fri Feb 09, 2018 2:28 am

Re: Setting focus to a Data Grid

Post by fritzdekatt » Thu Nov 14, 2019 11:21 pm

dunbarx wrote:
Thu Nov 14, 2019 10:53 pm
Just saw your latest post, which crossed mine in the mail.

A table field is just a field. But it contains the ability to create and overlay an ephemeral editable field that is sized and located dynamically on top of the "cell" where one clicks. Once its job is done, it populates the underlying cell with its contents, and then vanishes. It is a kluge, but a nice one.

Is the ephemeral field your "visual artifact?

Craig
That is totally wild. That explains a lot (and begs a lot of questions too). The ephemeral field seems to move around a lot and persist sometimes, as I believe you've noted from the tales of other forum members.

I will have to try the loops you spoke of in your previous post. So far I dump SQL into the fields and that's all she wrote.
As to why I want headers, some ledger sheets I have now (on the web or in spreadsheet form or in my database) extend beyond screen or form size. It's no problem to manually stick headers onto a grid with no horizontal scroll, but when it starts moving right you have an issue.

To specifically answer the question from your previous post (if you didn't pick it up by context from my last post), I think most programmers (and users) would like to select a cell just as they do in Excel or Filemaker or even an AJAX grid, wherein the cell has not just a location but a sequence in a row (and maybe triggers like mouseUp which I assume you can't do directly in a table field). This, and field specific formatting options, is the benefit of a "cell" that it appears a table field doesn't have. However, the fact that I can locate and select the actual field itself and then locate a specific row and virtual column is of some benefit. I guess the thing that would transcend the limitations of your second solution would be to select the column and row and then dynamically discover the location information and invoke your first solution. I just thought of that while I was writing this so I suppose after dinner I'll just have to try that out.

See, even when you're not giving me new data, the mere act of writing you back has given me some fresh idea (which will probably bomb like crazy and crash my Mac).

peace
fritz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9626
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting focus to a Data Grid

Post by dunbarx » Thu Nov 14, 2019 11:33 pm

That is what fun is all about.

But I am still puzzled by your puzzlement. You select a cell in Excel by clicking on that cell. You do EXACTLY the same with either a DG or a table field.

So then what is this all about:
Still, I'd like to be able to select and enter the table field via the keyboard. Why do they make just selecting a field so difficult? Or am I missing something?
in other words, as I said, how would you like to do this from the keyBoard? Such a method is not standard practice, but in LC, one can always kluge their way into (or out of) standard practice.

Craig

fritzdekatt
Posts: 57
Joined: Fri Feb 09, 2018 2:28 am

Re: Setting focus to a Data Grid

Post by fritzdekatt » Fri Nov 15, 2019 12:01 am

dunbarx wrote:
Thu Nov 14, 2019 11:33 pm
That is what fun is all about.

But I am still puzzled by your puzzlement. You select a cell in Excel by clicking on that cell. You do EXACTLY the same with either a DG or a table field.

So then what is this all about:
Still, I'd like to be able to select and enter the table field via the keyboard. Why do they make just selecting a field so difficult? Or am I missing something?
in other words, as I said, how would you like to do this from the keyBoard? Such a method is not standard practice, but in LC, one can always kluge their way into (or out of) standard practice.

Craig
It's my predilection to design input-intensive screens for maximum keyboard access, so I don't necessarily click on forms at all, even in dropdowns (or I design it to be optional).

I can accomplish this now by just tabbing into your "click on location" button, which will effectively give me keyboard access to the table field.

As to my idea from my last post about getting the location of the item inside the field, I (foolishly) didn't anticipate the dearth of a location property of anything inside the field. I can find the location of a field or a card, but I'm assuming I can't discover the location of a specific "field" inside the table field unless the mouse is in the location or there's text, whereas I can use mousechunk or something similar. (The API list in the Dictionary seems confined to database cursor properties so I'm searching on the web). I'm looking for just a "cursor location" right now. That would be the most direct route. Then I could use the location to "click on..." as in your example.

peace
fritz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9626
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting focus to a Data Grid

Post by dunbarx » Fri Nov 15, 2019 2:38 am

Fritz.
I'm looking for just a "cursor location" right now. That would be the most direct route. Then I could use the location to "click on..." as in your example.
First off, try this in the card script, assuming you have a field 2 that is available;

Code: Select all

on mouseMove
if the optionKey is down then put the mouseLoc into fld 2
end mouseMove
Move the cursor around the card a bit. So now we know about the mouseLoc.

But I am still not getting this. If you already have taken the time and trouble to set the cursor over the cell of interest, why add another layer to the process instead of simply clicking where you already are?

Beyond that, how exactly would you like to "enter" the table field from the keyboard? Perhaps if you do not care overmuch where you do in fact enter, thereafter being happy to use tabs and arrowKeys to navigate, then put this into the card script:

Code: Select all

 on rawKeyUp tKey
   if the controlKey is down and tKey = 115 then click at the loc of fld 1
 end rawKeyUp
Now anytime you want, hold the controlKey down and press "S". The phantom will appear near the center of the field, and you can arrowKey your way around the field all you want. And all this is strictly invoked from the keyboard. If this is anywhere near to what you wanted, think about my earlier thought, to use the topLeft of the table field to click at a more favorable cell, perhaps near the top, if that in fact makes any difference.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9626
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Setting focus to a Data Grid

Post by dunbarx » Fri Nov 15, 2019 3:11 pm

Fritz.
I will have to try the loops you spoke of in your previous post.
Make either a table field or a DG with several lines of data that span several columns. Put this in a button script somewhere:

Code: Select all

on mouseUp
   set the itemDel to tab
   get fld "yourTableField" -- if a table field
   get the dgText of grp "yourDG" --if a datagrid
   repeat for each line tLine in it
      put item 2 of tLine & return after accum
   end repeat
   answer accum
end mouseUp
Voila, column 2.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”