Add a new row to the table after each row

Table:

<table id='t1' style='border:1px solid #000000'>
    <tr>
      <td><span id='flight_1'>1</span></td><td>1</td>
    </tr>   

    <tr>
      <td><span id='flight_2'>2</span></td><td>2</td>
    </tr>  

    <tr>
      <td><span id='flight_99'>99</span></td><td>99</td>
    </tr> 
</table>

I want to find each identifier 'flight_xx', and then create a new line after the line belonging to the identifier 'flight_xx'.

Is this possible with jQuery?

The table is created using the DisplayTag library, and I cannot figure out how to do this.

+3
source share
5 answers

Try:

$('span[id^="flight"]').closest('tr').after('<tr>This is a new tr</tr>');

This will add a new line after lines containing spaces with identifiers starting with flight.

+3
source

Standard jQuery will look like this:

var search  = 99,
    new_row = '<tr><td></td></tr>';

$('#flight_' + search).closest('tr').after(new_row);
+2
source

:

$("#flight_" + flightNumber).closest('tr')
                            .after('<tr><td><New Cell!</td><td></td></tr>');

flgiht, flight_xx, , <tr> ( .closest() .after().

<span>, .closest() .

+2

Decorator. startRow(), - . - :

    public String startRow() {
    ...

    Item rowItem = (Item) getCurrentRowObject();

    if (rowItem has some value) {
        returnString = "<tr><td>some text here</td></tr>";
    }

    ...

    return returnString;

,

+1

finishRow. displayTag

    public  String finishRow()
                         {
                     String  returnString=null; 
                     ActorData rowItem = (ActorData) getCurrentRowObject();
                     if (rowItem.getAnyProperty()!=null )
                        {
                     returnString = "<tr><td>some text here</td><td colspan='2s'>avi</td>"
                    + "</tr>";
                         }
                     return returnString;
                         }
+1

Source: https://habr.com/ru/post/1761904/


All Articles