Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Naming table rows 1

Status
Not open for further replies.

Fingerprint

Programmer
Oct 21, 2002
35
GB
Hi all,

once again my text book fails me!
I am dynamically creating a table using databinding and some '*.csv' files, and I can't work out how to name the rows as they are created, or even reference which number row it is instead so that I can manipulate them later in the program.
Can anybody help?

- fingerprint
 
Quite likely you're looking for a chapter that doesn't exist yet. We're all struggling to understand this part.

An effective strategy for managing information imported into a table via databinding uses the JavaScript
Code:
this
keyword. In the general case the user selects a row of information by clicking it. You capture the event with --
Code:
<tr onclick=&quot;processRow(this);&quot;>
which transfers control to --
Code:
function processRow(Tr) { ... }
You have immediate access to the selected row,
Code:
Tr.cells[]
holds individual field elements,
Code:
Tr.style
is available for visual highlighting, etc. The job remains but you're at the right place.
 
Hey, it works!

Thanks for your help - I spent ages searching around MSDN only to find nothing.

- fingerprint
 
Hang on a minute though - (bad brain day), how do I select the whole row?

What I wanted to do was select a row, and highlight it on select (got the highlight bit), and then delete the row on a button push.

Urgh -not enough coffee...

- fingerprint
 
Deleting information isn't (shouldn't be) a trivial process. At the very least you'll have to tell the browser to redraw the screen omitting the current row. In the real world you'll have to get word back to whatever process created your '*.csv' files that this particular piece of information no longer exists and they'll have to take appropriate steps. Of course, sometimes the wrong piece of information disappears and life can get uncomfortable ...

You might want to take an increment approach -- add a status field to your row. Set this field to 'delete' when the button is pushed, perhaps &quot;lowlighting&quot; the entire row to give visual confirmation. This way 'delete' happens and 'undelete' is still an option.
 
It's not as bad as it sounds - I'm using a Tabular Data Control, not Remote Data Service, so all the delete will do is remove the record from the local cache.

Users are running this little program from their own computer, and using it to select the files to export to a database. Some records will be duplicates - almost the same info on different files, and the idea was to select a duplicate and be able to delete it.

Since this only needs to run in IE, I've been using Microsoft data binding code, and have found that using:

tdcName.recordset.Delete();

causes strange problems when you delete a record, then go to add more to the table, and is limited to deleting the first record in the table.

I wanted to either find a work-around, or find a way of telling the program which recordset to delete.
Think I'm a little over my head at the moment though.

I'll have a look at the status field idea, but I am limited to client-side scripting.

- fingerprint
 
Ok - so my code (abridged version) is now as follows:

Code:
<html>
<head>
	<title>Transporter</title>
<script language=&quot;javascript&quot;>
function addData()
 {
 var more
 more = document.givemore.loadthis.value;
 document.tdcInfo.dataURL = &quot;&quot;;
 document.tdcInfo.dataURL = more;
 document.tdcInfo.reset();
 }

function showme(tr)
{
 if (tr.style.backgroundColor != '#e6e6fa')
  {
  tr.style.backgroundColor = '#e6e6fa';
  }
 else
  {
  tr.style.backgroundColor = '#ffffff';
  }
}

function pushme()
{
 var str
 str = tdcInfo.recordset.recordCount;
 alert ( &quot;Number of records = &quot; + str);
}

</script>

<script for=&quot;btnDelete&quot; event=&quot;onclick&quot;>
 tdcInfo.recordset.AbsolutePosition = this.recordNumber;
 tdcInfo.recordset.Delete();
</script>

</head>

<body bgproperties=&quot;fixed&quot; bgcolor=&quot;honeydew&quot; vlink=&quot;#808080&quot; alink=&quot;#000000&quot; link=&quot;#000000&quot;>
<font face=&quot;verdana&quot;>



<div style=&quot;display:none&quot;>
<object id=&quot;tdcInfo&quot; classid=&quot;clsid:333C7BC4-460F-11D0-BC04-0080C7055A83&quot;>
	<param name=&quot;DataURL&quot; value=&quot;&quot;>								  
	<param name=&quot;UseHeader&quot; value=&quot;false&quot;>
	<param name=&quot;TextQualifier&quot; value=&quot;&quot;>
	<param name=&quot;appendData&quot; value=&quot;true&quot;>
</object>
</div>

<table id=&quot;trial&quot; name=&quot;trial&quot; datasrc=&quot;#tdcInfo&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; bordercolor=&quot;thistle&quot;>
<thead>
<tr style=&quot;font-weight:bold;font-size:10&quot; bgcolor=&quot;plum&quot;>
<td rowspan=&quot;2&quot; bgcolor=&quot;thistle&quot;> </td>
<td colspan=&quot;7&quot;>Employee and job details</td>
</tr>
<tr style=&quot;font-weight:bold;font-size:10&quot; bgcolor=&quot;lavender&quot;  align=&quot;center&quot;>
   <td>Job Title</td>
   <td>Emp. ID</td>
   <td>Job ID</td>
   <td>Grade</td>
   <td>Location</td>
   <td>Permanent<br>/Casual</td>
   <td>Tasks</td>
  </tr>
</thead>
<tbody>
<tr style=&quot;font-size:10;&quot; bgcolor=&quot;#ffffff&quot;  onclick=&quot;showme(this);&quot;>
<td bgcolor=&quot;#ffffff&quot;><button title=&quot;Delete this record&quot; id=&quot;btnDelete&quot; style=&quot;background-color:lavender;border-color:thistle;&quot;><b>X</b></button></td>
   <td><div datafld=&quot;Column1&quot;></div></td>
   <td><div datafld=&quot;Column2&quot;></div></td>
   <td><div datafld=&quot;Column3&quot;></div></td>
   <td><div datafld=&quot;Column4&quot;></div></td>
   <td><div datafld=&quot;Column5&quot;></div></td>
   <td><div datafld=&quot;Column6&quot;></div></td>
   <td><div datafld=&quot;Column7&quot;></div></td>
</tr>
</tbody>
</table>

<form name=&quot;givemore&quot;>
<input type=&quot;file&quot; name=&quot;loadthis&quot;>
<br><br>
<input type=&quot;button&quot; value=&quot;Display file&quot; onClick=&quot;{addData();}&quot; name=&quot;loader&quot; style=&quot;background-color:lavender;border-color:thistle;&quot;>
<input type=&quot;button&quot; value=&quot;Total records&quot; onClick=&quot;pushme();&quot; style=&quot;background-color:lavender;border-color:thistle;&quot;>
</form>


And it kinda works, but if you delete a row and then go to add some more rows, it either won't work, or takes ages and re-displays the files you've deleted.
I figure it has something to do with the reset bit, but I'm not sure.
Any ideas?

- fingerprint
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top