I don't know why I need true in the function. I just copied the code
from elsewhere ;) I am NOT a jquery (this is my first time using it)
or JS expert, so am just trying to cobble something together for a
work project, which is due by tomorrow.

I'm using this: http://www.isocra.com/2008/02/table-drag-and-drop-jquery-plugin/

to allow the table rows to be sortable. I was originally using the
id's for the tr tags that he had listed there in his example (i.e.
just numbers), but changed them to tr1, tr2, and so on just now, since
you say that numbers are not valid IDs . Doing that makes no
difference -- if I add a new row to the table, and try to change the
id, so that it will have an id different than the cloned row (and
thereby, hopefully be sortable), it just isn't happening. (if I use a
tool that lets me view the generated source, I can see that the ID has
not changed)

My Current code:

////javascript code

jQuery(document).ready(function() {
        jQuery('#table-1').tableDnD({
        onDrop: function(table, row) {
            //alert(jQuery('#table-1').tableDnDSerialize());
        },
        dragHandle: "dragHandle"
    });
        jQuery("#table-1 tr").hover(function() {
          jQuery(this.cells[0]).addClass('showDragHandle');
    }, function() {
          jQuery(this.cells[0]).removeClass('showDragHandle');
    });
});

function addTableRow(table)
{
        var clonedRow = jQuery(table + " tr:last").clone().attr({ id:
'tr13' }) ;
        jQuery(table).append(clonedRow);
    return true;

}


///// my html
<table id="table-1" cellspacing="0" cellpadding="2"><tr id="tr1"><td
class="dragHandle" width="16">&nbsp;&nbsp;</td>
<td>    <select id="athlete_ids[]" name="athlete_ids[]" class="pull-
down">
        <option value="0">None</option>
                <option value="9">, chris</option>
                <option value="517">, Willow</option>
</select>
</td>
</tr>
.
.
.
(duplicated multiple times, with tr2, tr3, and so on as the ids)
</table>

My specific test example has 12 rows in it. I'm trying to add the 13th
row (hence why tr13 is currently hardcoded. I'll worry later about
trying to figure out how many rows there are in the table. I just want
to get the darn id to change, so I can sort any added rows!)


On Mar 23, 7:48 pm, Karl Swedberg <k...@englishrules.com> wrote:
> A few things:
> 1.  Why do you need return true in the function?
> 2.  "13" is not a valid ID,
> 3.  you should probably be appending the row to a tbody, not the table.
>
> Nevertheless, I just tried your first function and it seemed to work  
> fine for me:
>
> http://jsbin.com/ideju/edit
>
> Does that work for you?
>
> --Karl
>
> ____________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On Mar 23, 2009, at 10:11 PM, rivkadr wrote:
>
>
>
> > Am getting bloody from beating my head against the wall. I just want
> > to be able to change the id of a table row that is cloned and appended
> > to a table. This shouldn't be so hard, no?
>
> > Here's what I've tried:
>
> > function addTableRow(table)
> > {
> >    var clonedRow = jQuery(table + " tr:last").clone().attr({ id:
> > '13' }) ;
> >    jQuery(table).append(clonedRow);
> >    return true;
> > }
>
> > OR
>
> > function addTableRow(table)
> > {
> >    var clonedRow = jQuery(table + " tr:last").clone();
> >    jQuery(clonedRow).attr("id", "13");  //yes, I want the id to be 13
> >    jQuery(table).append(clonedRow);
> >    return true;
> > }
>
> > Neither of the above works. Anyone got any help they can give me,
> > please?

Reply via email to