Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
8 lars 1
/**
2
 * This method will add an existing `dt-tag tr` element to a DataTable. This can
3
 * be useful for maintaining custom classes and other attributes which have
4
 * been explicitly assigned to the row.
5
 *
6
 * DataTables 1.10+ has `dt-api row.add()` and `dt-api rows.add()` which have
7
 * this ability built in, and extend it to be able to use jQuery objects as well
8
 * as plain `dt-tag tr` elements. As such this method is marked deprecated, but
9
 * is available for use with legacy version of DataTables. Please use the
10
 * new API if you are used DataTables 1.10 or newer.
11
 *
12
 *  @name fnAddTr
13
 *  @summary Add a `dt-tag tr` element to the table
14
 *  @author [Allan Jardine](http://sprymedia.co.uk)
15
 *  @deprecated
16
 *
17
 *  @param {node} nTr `dt-tag tr` element to add to the table
18
 *  @param {boolean} [bRedraw=false] Indicate if the table should do a redraw or not.
19
 *
20
 *  @example
21
 *    var table = $('#example').dataTable();
22
 *    table.fnAddTr( $('<tr>'+
23
 *         '<td>1</td>'+
24
 *         '<td>2</td>'+
25
 *         '<td>3</td>'+
26
 *      '</tr>')[0]
27
 *    );
28
 */
29
 
30
jQuery.fn.dataTableExt.oApi.fnAddTr = function ( oSettings, nTr, bRedraw ) {
31
    if ( typeof bRedraw == 'undefined' )
32
    {
33
        bRedraw = true;
34
    }
35
 
36
    var nTds = nTr.getElementsByTagName('td');
37
    if ( nTds.length != oSettings.aoColumns.length )
38
    {
39
        alert( 'Warning: not adding new TR - columns and TD elements must match' );
40
        return;
41
    }
42
 
43
    var aData = [];
44
    var aInvisible = [];
45
    var i;
46
    for ( i=0 ; i<nTds.length ; i++ )
47
    {
48
        aData.push( nTds[i].innerHTML );
49
        if (!oSettings.aoColumns[i].bVisible)
50
        {
51
            aInvisible.push( i );
52
        }
53
    }
54
 
55
    /* Add the data and then replace DataTable's generated TR with ours */
56
    var iIndex = this.oApi._fnAddData( oSettings, aData );
57
    nTr._DT_RowIndex = iIndex;
58
    oSettings.aoData[ iIndex ].nTr = nTr;
59
 
60
    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
61
 
62
    // Hidding invisible columns
63
    for ( i = (aInvisible.length - 1) ; i >= 0 ; i-- )
64
    {
65
		oSettings.aoData[iIndex]._anHidden[ i ] = nTds[aInvisible[i]];
66
		nTr.removeChild( nTds[aInvisible[i]] );
67
    }
68
 
69
	// Redraw
70
    if ( bRedraw )
71
    {
72
        this.oApi._fnReDraw( oSettings );
73
    }
74
};