As other's have said, you should do this server-side. Anyway, here's a
way to do it:

var csv = 'Row2,Row1,Row3',
    mytable = $('#mytable')[0]; //save the table for later
csv = csv.split(','); //csv is now an array

var ln = csv.length;
while(ln--){ //loop csv array in reverse
   $('#'+csv[ln]) //build the id string #rowX
      .prependTo(mytable);
}

<table id="mytable">
<tr id="Row1">
  <td>Some label 1 </td>
  <td>Some complex control</td>
</tr>
<tr id="Row2">
  <td>Some label 2</td>
  <td>Some complex control</td>
</tr>
<tr id="Row3">
  <td>Some label 3</td>
  <td>Some complex control</td>
</tr>
</table>

cheers,
- ricardo

On Mar 3, 3:54 pm, spdude <sandeshm...@gmail.com> wrote:
> anyone?
>
> On Mar 3, 8:51 am, spdude <sandeshm...@gmail.com> wrote:
>
> > I dont want to sort the table. Rather, I want to reorder the <tr>
> > based on a csv of the tr ids. This csv can be from the db, viewstate
> > or session.
>
> > I would rather not add the controls dynamically to the table as the
> > rows have a lot of complicated custom controls and adding them
> > dynamically may open up other issues with viewstate etc.
>
> > On Mar 3, 7:02 am, Rasit OZDAS <rasitoz...@gmail.com> wrote:
>
> > > If I understand your problem correctly, you don't need JQuery for this,
> > > you can just create rows dynamically on start.
>
> > > JQuery is needed only when you need to change sorting in the middle, using
> > > Ajax etc.
> > > Tablesorter doesn't sort as you want, it sorts like "ORDER BY" query in 
> > > SQL.
>
> > > I recommend using Jquery Sortable (in JQuery-UI).
>
> > > Rasit
>
> > > 2009/3/3 spdude <sandeshm...@gmail.com>
>
> > > > I have an aspx page that looks something like this:
>
> > > > <tr id="Row1">
> > > >  <td>Some label</td>
> > > >  <td>Some complex control</td>
> > > > </tr>
> > > > <tr id="Row2">
> > > >  <td>Some label</td>
> > > >  <td>Some complex control</td>
> > > > </tr>
> > > > <tr id="Row3">
> > > >  <td>Some label</td>
> > > >  <td>Some complex control</td>
> > > > </tr>
>
> > > > As soon as the page is loaded, I would want to reorder these rows
> > > > based on the user's previously selected order (stored in a database)
>
> > > > How would I use JQuery/JS to accomplish this?
>
> > > --
> > > M. Raşit ÖZDAŞ

Reply via email to