Add href and img with fnAddData

Add href and img with fnAddData

fernandopaivafernandopaiva Posts: 6Questions: 1Answers: 0
edited May 2013 in DataTables 1.9
Hello all

I am trying add a href and img in my DataTable but in the column show only [object Object]

I'm trying below

[code]
function addRegistrosTabela(output){
var obj = output;
var links = [];

for(i in obj){
var editar = $('',{
title: 'Edit',
href: "../controls/YCurriculumController.php?action=editarCurriculum&id=" + obj[i].id_curriculum
}).append($('')
.attr("src","../imagens/editIcon.png"));

var deletar = $('',{
title: 'Delete',
href: "../controls/YCurriculumController.php?action=deletarCurriculum&id=" + obj[i].id_curriculum
}).append($('')
.attr("src","../imagens/deleteIcon.png"));

$('#idTabela').dataTable().fnAddData([
obj[i].id_curriculum,
obj[i].nome,
obj[i].cpf,
obj[i].endereco,
obj[i].bairro,
obj[i].cidade,
obj[i].fone1,
obj[i].celular,
obj[i].email,
obj[i].cargo,
editar, //here show [object]
deletar //here show [object]
]);
[/code]

Replies

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    fnAddData can't be used to add nodes as you are doing above. The upgrade in 1.10 should allow this, but currently this is not possible. I'd suggest building the HTML string rather than the node.

    Allan
  • fernandopaivafernandopaiva Posts: 6Questions: 1Answers: 0
    Hi Allan, thanks for your answer !!!

    How I building the HTML string with my node ?

    thanks
  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Just use `editor = '';` etc.

    Allan
  • fernandopaivafernandopaiva Posts: 6Questions: 1Answers: 0
    I understand Allan, but the DataTable accept add lines without use fnAddData ?

    I am trying this.

    [code]
    //html


    ID
    Actions




    //javascript
    $(document).ready(function(){
    var i = 0;
    while(i < 10){
    var edit = "Edit";
    $("#mytable > tbody").append("");
    $("#mytable > tbody").append("" + i + "");
    $("#mytable > tbody").append("" + edit + "");
    $("#mytable > tbody").append("");
    i++;
    }
    });

    [/code]


    thanks
  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    No - fnAddData or one of the plug-in API methods (such as fnAddTr) are the only ways. See: http://datatables.net/faqs#append

    The ability to add TR nodes using `row.add( node )` will be available in v1.10.

    Allan
  • fernandopaivafernandopaiva Posts: 6Questions: 1Answers: 0
    now work.

    thanks Allan
This discussion has been closed.