PDA

View Full Version : Sorting a table that contains buttons


ndpace
12-20-2002, 12:15 AM
I have a users table that I am building with ASP. The last 2 columns contain submit buttons, one to edit the user and one to change the users password. When I use the javascript code below to sort the columns, the sort works fine but the buttons disapear. Is there a solution using javascript?

Thanks, Jim





<script Language="JavaScript">
<!--
var lastcol, lastseq;
function f_sort( ao_table, ai_sortcol, ab_header )
{
var ir, ic, is, ii, id;

ir = ao_table.rows.length;
if( ir < 1 ) return;

ic = ao_table.rows[1].cells.length;
// if we have a header row, ignore the first row
if( ab_header == true ) is=1; else is=0;

// take a copy of the data to shuffle in memory
var row_data = new Array( ir );
ii=0;
for( i=is; i < ir; i++ )
{
var col_data = new Array( ic );
for( j=0; j < ic; j++ )
{
col_data[j] = ao_table.rows[i].cells[j].innerText;
}
row_data[ ii++ ] = col_data;
}

// sort the data
var bswap = false;
var row1, row2;

if( ai_sortcol != lastcol )
lastseq = 'A';
else
{
if( lastseq == 'A' ) lastseq = 'D'; else lastseq = 'A';
}

// if we have a header row we have one less row to sort
if( ab_header == true ) id=ir-1; else id=ir;
for( i=0; i < id; i++ )
{
bswap = false;
for( j=0; j < id - 1; j++ )
{
// test the current value + the next and
// swap if required.
row1 = row_data[j];
row2 = row_data[j+1];
if( lastseq == "A" )
{
if( row1[ ai_sortcol ] > row2[ ai_sortcol ] )
{
row_data[j+1] = row1;
row_data[j] = row2;
bswap=true;
}
}
else
{
if( row1[ ai_sortcol ] < row2[ ai_sortcol ] )
{
row_data[j+1] = row1;
row_data[j] = row2;
bswap=true;
}
}
}
if( bswap == false ) break;
}

// load the data back into the table
ii = is;
for( i=0; i < id; i++ )
{
row1 = row_data[ i ];
for( j=0; j < ic; j++ )
{
ao_table.rows[ii].cells[j].innerText = row1[j];
}
ii++;
}
lastcol = ai_sortcol;
}
//--></script>