diff --git a/js/core/core.draw.js b/js/core/core.draw.js index 9a197fc54..ba8b3554d 100644 --- a/js/core/core.draw.js +++ b/js/core/core.draw.js @@ -62,7 +62,7 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds ) for ( i=0, iLen=oSettings.aoColumns.length ; i') - .appendTo( target ); - - for ( i=0, ien=columns.length ; i') - .html( columns[i][titleProp] || '' ) - .appendTo( row ); + if (side === 'header' || _pluck(settings.aoColumns, titleProp).join('')) { + row = $('tr', target); + + // Add a row if needed + if (! row.length) { + row = $('').appendTo(target) + } + + // Add the number of cells needed to make up to the number of columns + if (row.length === 1) { + var cells = $('td, th', row); + + for ( i=cells.length, ien=columns.length ; i') + .html( columns[i][titleProp] || '' ) + .appendTo( row ); + } } } diff --git a/test/functional/init/additionalColumns.js b/test/functional/init/additionalColumns.js new file mode 100644 index 000000000..f0899cf41 --- /dev/null +++ b/test/functional/init/additionalColumns.js @@ -0,0 +1,38 @@ +describe('Empty DataTable', function() { + dt.libs({ + js: ['jquery', 'datatables'], + css: ['datatables'] + }); + + dt.html('basic'); + + it('DataTables can be initialised with an extra column', function() { + new DataTable('#example', { + columns: [ + null, + null, + null, + null, + null, + null, + { title: 'Title', defaultContent: 'Content' } + ] + }); + + // No JS errors occurred + expect(true).toEqual(true); + }); + + it('Last title contains set title', function() { + expect($('thead tr:first-child th:last-child').text()).toBe('Title'); + }); + + it('Last column contains default content', function() { + expect($('tbody tr:first-child td:last-child').text()).toBe('Content'); + }); + + it('And first column is as expected', function() { + expect($('thead tr:first-child th:first-child').text()).toBe('Name'); + expect($('tbody tr:first-child td:first-child').text()).toBe('Airi Satou'); + }); +});