From 903d1219f3c5218e8f76dc3c96556378ef4c0870 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Sat, 18 May 2013 17:39:03 +0100 Subject: [PATCH] New: table() API methods - New API methods: - table() - select a single table - table().node() - get the table node for the table - To be honest, these methods are not likely to be used particuarly often, so I think they are fairly low priority, but they could provide useful, and it is a public way to get the table node. --- media/src/api/api.row.js | 2 +- media/src/api/api.table.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/media/src/api/api.row.js b/media/src/api/api.row.js index a737ea95..5dc54558 100644 --- a/media/src/api/api.row.js +++ b/media/src/api/api.row.js @@ -18,7 +18,7 @@ _api.register( 'row()', function ( selector, opts ) { _api.register( 'row().node()', function () { var ctx = this.context; - + if ( ctx.length && this.length ) { return ctx[0].aoData[ this[0] ].nTr || undefined; } diff --git a/media/src/api/api.table.js b/media/src/api/api.table.js index 9367cecf..2c21ec32 100644 --- a/media/src/api/api.table.js +++ b/media/src/api/api.table.js @@ -36,5 +36,28 @@ _Api.register( 'tables().nodes()', function () { } ); +_Api.register( 'table()', function ( selector ) { + var tables = this.tables( selector ); + var ctx = tables.context; + + // Truncate to the first matched table + if ( ctx.length ) { + ctx.length = 1; + } + + return tables; +} ); + + +_Api.register( 'table().node()', function () { + var ctx = this.context; + + if ( ctx.length ) { + return ctx[0].nTable; + } + // return undefined; +} ); + + }());