I was wondering if is it possible to put a data-title option into my <td>
tag using angular-datatables.
I would like to see my result HTML like this:
<table> <thead> <tr> <th>Id</th> <th>First Name</th> <th>Last Name</th> </tr> </thead> <tbody> <tr> <td data-title="Id">01</td> <td data-title="First Name">Paul</td> <td data-title="Last Name">Summer</td> </tr> </tbody> </table>
This is my example code: http://embed.plnkr.co/K24WFju44neYFRfwBxfK/
Note: Unfortunately I can't use ng-repeat for this, I must put everything on the controller side.
Look at createdCell
. If you want to target a single column (or want different callbacks for each column) use the DTColumnBuilder
as in your link :
DTColumnBuilder.newColumn('firstName')
.withTitle('First name')
.withOption('createdCell', function (td, cellData, rowData, row, col) {
$(td).attr('data-title', cellData) //setting the value as title as test
}),
...
I dont know what you want to place in data-title, so I just populate with the cell value. If you want to populate a data-title
to every column, you can use DTColumnDefBuilder
to implement a generic handler :
vm.DTColumnDefs = [
DTColumnDefBuilder
.newColumnDef(-1)
.withOption('createdCell', function (td, cellData, rowData, row, col) {
$(td).attr('data-title', cellData)
})
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.