473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

interactive table - please help

hi

i'm new to javascript. i'm hoping to get some help and find out if
what i want to do is possible and - assuming it is, get some tips on
how to accomplish the task.

ok - assume i have a table, the contents of which are dynamic. there
can be any number of rows in this table - somewhere between 50 and 500
would be the range. in each row - there can be any number of td's.
the relative 'width' of a td in a tr is specified by a td's colspan.
the sum of all colspans for the td's in every tr is the same -the
table is 'well formatted'. here's a rough ascii representation of
this table ...

Note: entries in this table are identified by "tr-i|td-j", so the 3rd
'td' in the 2nd 'tr' would be "tr-2|td-3". the '@' character separates
individual td's.

@-----------------------------------------------------------@
@ tr-1|td-1 @ tr-1|td-2 @
@-----------------------------------------------------------@
@ tr-2|td-1 @ tr-2|td-2 @ tr-2|td-3 @
@-----------------------------------------------------------@
@ tr-3|td-1 @
@-----------------------------------------------------------@
@ tr-4|td-1 @ tr-4|td-2 @ tr-4|td-3 @ tr-4|td-4 @
@-----------------------------------------------------------@

that's how a sample table looks

[note: in my editor the above table is well formatted as well as in a
test post message read via groups.google.com. however in my news
reader it is not 'well-formatted. i apologize if the posting arives
with screwed-up formatting]

this is how 'it' functions

- the table maintains 'focus' with respect to the td's or 'cells'
within a given tr or 'row'. 'focus' being defined as some visual
indication that the cell in question is different than cell's that do
not have the 'focus'. its really as simple as the focused cell having
a different background color than the others. when the focus moves to
another cell - that's cell's color changes. only one cell can have the
'focus' at a time.

- when the table is first displayed, some arbitrary cell has the
'focus'. for simplicity sake - say the first cell in the first row.

- the user can 'navigate' the table - aka change the cell that has the
focus, by using the keyboard or the mouse. the keyboard changes the
focus via the up, down, left, and right keys.

- keyboard navigation with the left/right keys is straight forward.
if the use presses the right arrow key, the focus moves to the cell to
the right of the focused cell. if the current focused cell is the last
cell in a row, then the focus does not change - but the javascript code
is aware that an 'edge' has been 'hit'. the left arrow key functions
similarly - just in the opposite direction

- keyboard navigation with the up/down keys is not as straight forward
as left/right. up/down focus transitions are dictated by first
identifying the left 'edge' of the cell with the current focus and then
finding the cell in the next row - be it above or below depending on
which key was hit, that overlaps with the left 'edge' of the previously
focused cell. describing several transitions should make the logic
clear. say the focus is currently on the first cell in the first row.
in the table above that would be tr-1|td-1

- user hits the right arrow key -focus is now tr-1|td-2
- user hits the down arrow key -focus is now tr-2|td-2
- user hits the down arrow key -focus is now tr-3|td-1
- user hits the down arrow key -focus is now tr-4|td-2
- user hits the right arrow key -focus is now tr-4|td-3
- user hits the right arrow key -focus is now tr-4|td-4
- user hits the up arrow key -focus is now tr-3|td-1
- user hits the up arrow key -focus is now tr-2|td-3

- if the user - while navigating vertically, reaches either the top or
bottom of the table, the javascript is aware of this event

- the user can use the mouse to change the 'focus' to any visible cell.

- the javascript code traps the return/enter key and performs some
arbitrary action when this happens. for example - causes the cell with
the current focus to blink.

- ideally - it would also be great if the right button mouse click
could be 'trapped', and when that happens the javascript would know on
top of which cell this key-press occurred. this key-press does not
have to occur over the currently 'focused' cell

if you made it this far - thanks for sticking with me. any
tips/pointers/relevant advice is extremely appreciated. if anyone
knows of any existing sample code that demonstrates any portion of the
aforementioned functionality i would be eternally grateful if you sent
me links.

thanks
dave

Feb 3 '07 #1
2 2072
Hi Dave,

On Feb 3, 9:22 am, Dave Ekhaus <dekh...@mac.comwrote:
i'm new to javascript.
<URL: http://jibbering.com/faq/>
<URL: http://jibbering.com/faq/#FAQ3_1watch for errata!
<URL: http://groups.google.com/group/comp....avascript/msg/
04a7a303c2e67280>
i'm hoping to get some help and find out if
what i want to do is possible and - assuming it is, get some tips on
how to accomplish the task.
Start with the simplest example and slowly build up.

[snip about having a table where a cell has focus and the focus can be
changed by arrows and mouse clicks]

I haven't tried this with arrows keys but is sounds fine in prinicple.
I know that arrow keys can be observed at least in the popular
browsers now.

<URL: http://www.dustindiaz.com/basement/tetris.html>

- ideally - it would also be great if the right button mouse click
could be 'trapped', and when that happens the javascript would know on
top of which cell this key-press occurred. this key-press does not
have to occur over the currently 'focused' cell
I think hijacking right clicks is asking for trouble. More importantly
the user probably wants the right click menu to work the same in all
pages. Right click should be under the user/browser control.

<URL: http://jibbering.com/faq/#FAQ4_27>

Peter

Feb 3 '07 #2
On Sat, 03 Feb 2007 09:22:30 -0800, Dave Ekhaus wrote:
hi

i'm new to javascript. i'm hoping to get some help and find out if
what i want to do is possible and - assuming it is, get some tips on
how to accomplish the task.

ok - assume i have a table, the contents of which are dynamic. there
can be any number of rows in this table - somewhere between 50 and 500
would be the range. in each row - there can be any number of td's.
the relative 'width' of a td in a tr is specified by a td's colspan.
the sum of all colspans for the td's in every tr is the same -the
table is 'well formatted'. here's a rough ascii representation of
this table ...

Note: entries in this table are identified by "tr-i|td-j", so the 3rd
'td' in the 2nd 'tr' would be "tr-2|td-3". the '@' character separates
individual td's.

@-----------------------------------------------------------@
@ tr-1|td-1 @ tr-1|td-2 @
@-----------------------------------------------------------@
@ tr-2|td-1 @ tr-2|td-2 @ tr-2|td-3 @
@-----------------------------------------------------------@
@ tr-3|td-1 @
@-----------------------------------------------------------@
@ tr-4|td-1 @ tr-4|td-2 @ tr-4|td-3 @ tr-4|td-4 @
@-----------------------------------------------------------@

that's how a sample table looks

[note: in my editor the above table is well formatted as well as in a
test post message read via groups.google.com. however in my news
reader it is not 'well-formatted. i apologize if the posting arives
with screwed-up formatting]

this is how 'it' functions

- the table maintains 'focus' with respect to the td's or 'cells'
within a given tr or 'row'. 'focus' being defined as some visual
indication that the cell in question is different than cell's that do
not have the 'focus'. its really as simple as the focused cell having
a different background color than the others. when the focus moves to
another cell - that's cell's color changes. only one cell can have the
'focus' at a time.

- when the table is first displayed, some arbitrary cell has the
'focus'. for simplicity sake - say the first cell in the first row.

- the user can 'navigate' the table - aka change the cell that has the
focus, by using the keyboard or the mouse. the keyboard changes the
focus via the up, down, left, and right keys.

- keyboard navigation with the left/right keys is straight forward.
if the use presses the right arrow key, the focus moves to the cell to
the right of the focused cell. if the current focused cell is the last
cell in a row, then the focus does not change - but the javascript code
is aware that an 'edge' has been 'hit'. the left arrow key functions
similarly - just in the opposite direction

- keyboard navigation with the up/down keys is not as straight forward
as left/right. up/down focus transitions are dictated by first
identifying the left 'edge' of the cell with the current focus and then
finding the cell in the next row - be it above or below depending on
which key was hit, that overlaps with the left 'edge' of the previously
focused cell. describing several transitions should make the logic
clear. say the focus is currently on the first cell in the first row.
in the table above that would be tr-1|td-1

- user hits the right arrow key -focus is now tr-1|td-2
- user hits the down arrow key -focus is now tr-2|td-2
- user hits the down arrow key -focus is now tr-3|td-1
- user hits the down arrow key -focus is now tr-4|td-2
- user hits the right arrow key -focus is now tr-4|td-3
- user hits the right arrow key -focus is now tr-4|td-4
- user hits the up arrow key -focus is now tr-3|td-1
- user hits the up arrow key -focus is now tr-2|td-3

- if the user - while navigating vertically, reaches either the top or
bottom of the table, the javascript is aware of this event

- the user can use the mouse to change the 'focus' to any visible cell.

- the javascript code traps the return/enter key and performs some
arbitrary action when this happens. for example - causes the cell with
the current focus to blink.

- ideally - it would also be great if the right button mouse click
could be 'trapped', and when that happens the javascript would know on
top of which cell this key-press occurred. this key-press does not
have to occur over the currently 'focused' cell

if you made it this far - thanks for sticking with me. any
tips/pointers/relevant advice is extremely appreciated. if anyone
knows of any existing sample code that demonstrates any portion of the
aforementioned functionality i would be eternally grateful if you sent
me links.

thanks
dave
Dave,

Your first, and most critically important step, should be to separate and
abstract the data you're representing with the table from the table
itself. In more general terms, ensure that you partition your code so that
you have a data structure (a 2D array of objects for example), usually
referred to as the "model", from the visual representation of that data
(an HTML table), usually referred to as the "view".

One of the biggest and most expensive traps you can fall into is to
combine the model and view within the html table itself. This has the
unfortunate side-effect of forcing you to use fragile methods like parsing
and updating the table HTML dynamically - nothing like this approach for
generating poor code.

Instead:

1) Create a 2D abstract structure of some kind to model the data your
table will display.

2) Dynamically generate the table itself from this data structure.
Consider adding an ID or somesuch to each cell that allows you to refer
back to the relate entry in your structure when an event is generated.

3) When you respond to events, use this ID to determine which point in the
data model is related, and base your actions on this. This may involve,
for instance, checking that your vertical index doesn't fall outside the
bounds of your data structure, rather inspecting the DOM to see if you've
fallen off the end of the table.

If you follow this pattern, you'll end up with a more robust, logical and
flexible solution.

Sean
Feb 3 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

147
by: Sateesh | last post by:
Hi, I am a beginner in Python, and am wondering what is it about the indentation in Python, without which python scripts do not work properly. Why can't the indentation not so strict so as to give...
6
by: Avi Berkovich | last post by:
Hello, I was unable to use popen2.popen4 to grab python.exe's (2.3) output, for starts, it doesn't show the version information at the beginning and won't return anything when writing to the...
20
by: Joe | last post by:
When you run "python -i scriptname.py" after the script completes you left at the interactive command prompt. Is there a way to have this occur from a running program? In other words can I...
6
by: Ken Fine | last post by:
(originally posted to one of macromedia's groups; no help, so hopefully someone here can help me out. I'm using VBScript ASP.) When designing administrative interfaces to websites, we often need...
0
by: Diego Zeballos Fraigne | last post by:
Hi there, we have a problem when using NetDDE from a non-interactive session Our solution is a VB6 program which - among other things - requests data from a DDE server. The program is not a...
5
by: sugaray | last post by:
Right now, the code I wrote below seems works fine, i know it's definitely not the best solution, so if there are better solutions to eschew from using goto statements to jump out of multiple loops...
2
by: WJ | last post by:
I have three ASPX pages: 1. "WebForm1.aspx" is interactive, responsible for calling a web site (https://www.payMe.com) with $$$. It is working fine. 2. "WebForm2.aspx" is non-interactive, a...
13
by: dmh2000 | last post by:
I am experimenting with the interactive interpreter environments of Python and Ruby and I ran into what seems to be a fundamental difference. However I may be doing something wrong in Python....
2
by: sharath067 | last post by:
I want to dynamically update the scatter plot based on the y-axis data received from a socket connection. I used python matplot lib in interactive mode to do this, but during dynamic updation if i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.