Problems using fnUpdate with dataTables 1.9.4

Problems using fnUpdate with dataTables 1.9.4

adrianFerreiraadrianFerreira Posts: 9Questions: 2Answers: 0

Hi Alan, please help me xDD

Im using dataTables on my code. I'm trying to update one single row, using this code:

//$('#tableParameters_'+identificadorPerfilado).dataTable().fnUpdate({id:'1', aplicacion:aplicacionAuxM, perfil:codigoPerfilAuxM, idioma:codigoIdiomaAuxM, nombre:nombreLinkP, valor:valor, 8}, numFila);
//$('#tableParameters_'+identificadorPerfilado).dataTable().fnUpdate({'1', aplicacionAuxM, codigoPerfilAuxM, codigoIdiomaAuxM, nombreLinkP, valor, 8}, numFila);
//$('#tableParameters_'+identificadorPerfilado).dataTable().fnUpdate([id:'1', aplicacion:aplicacionAuxM, perfil:codigoPerfilAuxM, idioma:codigoIdiomaAuxM, nombre:nombreLinkP, valor:valor, 8], numFila);
//$('#tableParameters_'+identificadorPerfilado).dataTable().fnUpdate(['1', aplicacionAuxM, codigoPerfilAuxM, codigoIdiomaAuxM, nombreLinkP, valor, 8], numFila);

I have 7 columns on my table, and the last one is the classic column with edit and delete buttons.

numFila is a number, the number of the row y want to update. i figured it out creating a numFila por each row at the fnCreatedRow of the oInit.

I was able to add a row whit this sentence:

$('#tablaParameters_'+identificadorPerfilado).dataTable().fnAddData({id:'1', aplicacion:aplicacionAux, perfil:codigoPerfilAux, idioma:codigoIdiomaAux, nombre:nombreLinkP, valor:valor, data:'8'});

As you can read, 2º and 3º options are not right written, js compleins. So i tried first and last one.
I can not use a regular $('#XXXX') example, because y I have a dynamic number of tables.

So, i dont know if i'm not writting the code right, or if giving the fnUpdate just a number, (numFila) y also wrong.

Thanks so much for any help.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • adrianFerreiraadrianFerreira Posts: 9Questions: 2Answers: 0

    Sorry Colin, i'm not able to link you to an test case. But any help you give me will be very helpful.

    I'll try to explain better my problem. I have a table on my .jsp page, and then on js y define it as dataTable.

    I have the classic pencil icon, and when y click on it, y star an js function call editParam().
    The final situacion is that at the end of that function, y need to update a row of my datatable.
    Previously of clicking on the pencil, I use the dataTable funcion of fnCreatedRow (sorry for the spanish name of variables xD):

        "fnCreatedRow": function(nRow, aData, iDataIndex){  
    
            var nombre = aData['nombre'];
            var valor = aData['valor'];
            var aplicacion = aData['aplicacion'];
            var perfil = aData['perfil'];
            var idioma = aData['idioma'];
            var id = aData['id'];
    
            var global = aplicacion+'_'+perfil+'_'+idioma;
            var nRowString = nRow._DT_RowIndex;
    
            $('td:eq(2)',nRow).html('<a href="javascript:editParam(\''+nombre+'\',\''+valor+'\',\''+global+'\',\''+id+'\',\''+nRowString+'\')"><i class="icono-editar" title="Editar"></i></a><a href="javascript:deteleParam(\''+nombre+'\',\''+valor+'\',\''+global+'\',\''+id+'\',\''+nRowString+'\')"><i class="icono-borrar" title="Eliminar"></i></a>');
        },
    

    When i click on my pencil, I show a pop-up window, fill a small form, and click on the save button of my pop-up. I star my save button onClick function, and, after modify my Data base, y need to update visualy the dataTable. Thats the point where I star this function:

    function modify(nombreLinkP, valor, identificadorPerfilado, numFila){

    var aplicacionAuxM = identificadorPerfilado.split("_")[0];
    var codigoPerfilAuxM = identificadorPerfilado.split("_")[1];
    var codigoIdiomaAuxM = identificadorPerfilado.split("_")[2];;
    
    var tableName= "tablaParameters_"+identificadorPerfilado;
    t=$('#'+tableName).dataTable();
    
    
    //$('#tablaParameters_'+identificadorPerfilado).dataTable().fnUpdate({id:'1', aplicacion:aplicacionAuxM, perfil:codigoPerfilAuxM, idioma:codigoIdiomaAuxM, nombre:nombreLinkP, valor:valor}, numFila);
    
    //$('#tablaParameters_'+identificadorPerfilado).dataTable().fnUpdate(['1', aplicacionAuxM, codigoPerfilAuxM, codigoIdiomaAuxM, nombreLinkP, valor, 8], numFila);
    

    }
    My table has 7 colums: id, aplicacion, pefil, idioma, nombre, valor, and the icons column. That '8' you see is a random number just to fill that column.

    When I use the first line of the code above, I get on console the message: Cant get the 'nTr' propierty ... (something similar, my browser its in spanish.)
    When I use the second line, I get a pop-up advise onde browser that sais:
    "datatables warning (table id = 'tableParameters_1_DEFAULT_es'): requested unknown parameter 'id' from the datasource for row2"

    More information, numFila = nRowString, the variable I got when I created the row.

    I think that my problem it's just the way I write the code, something its missing.

    I don´t know if that will be usefull, but this line for adding a row to a dataTable its working for me:

    $('#tablaParameters_'+identificadorPerfilado).dataTable().fnAddData({id:'1', aplicacion:aplicacionAux, perfil:codigoPerfilAux, idioma:codigoIdiomaAux, nombre:nombreLinkP, valor:valor, data:'8'});

    Sorry for such a long post, i'm kinda desperate, imaging my situation, today, in spain is holyday xDD.

    Thank for any help

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    There's a lot going on there, we would really need to see it. If you can't link to your page, please create a test case on http://live.datatables.net/ that replicates the issue, it'll help us to help you,

    Colin

  • adrianFerreiraadrianFerreira Posts: 9Questions: 2Answers: 0

    Sorry Colin, i'm not able to link you to an test case. But any help you give me will be very helpful.

    I'll try to explain better my problem. I have a table on my .jsp page, and then on js y define it as dataTable.

    I have the classic pencil icon, and when y click on it, y star an js function call editParam().
    The final situacion is that at the end of that function, y need to update a row of my datatable.
    Previously of clicking on the pencil, I use the dataTable funcion of fnCreatedRow (sorry for the spanish name of variables xD):

        "fnCreatedRow": function(nRow, aData, iDataIndex){  
    
            var nombre = aData['nombre'];
            var valor = aData['valor'];
            var aplicacion = aData['aplicacion'];
            var perfil = aData['perfil'];
            var idioma = aData['idioma'];
            var id = aData['id'];
    
            var global = aplicacion+'_'+perfil+'_'+idioma;
            var nRowString = nRow._DT_RowIndex;
    
            $('td:eq(2)',nRow).html('<a href="javascript:editParam(\''+nombre+'\',\''+valor+'\',\''+global+'\',\''+id+'\',\''+nRowString+'\')"><i class="icono-editar" title="Editar"></i></a><a href="javascript:deteleParam(\''+nombre+'\',\''+valor+'\',\''+global+'\',\''+id+'\',\''+nRowString+'\')"><i class="icono-borrar" title="Eliminar"></i></a>');
        },
    

    When i click on my pencil, I show a pop-up window, fill a small form, and click on the save button of my pop-up. I star my save button onClick function, and, after modify my Data base, y need to update visualy the dataTable. Thats the point where I star this function:

    function modify(nombreLinkP, valor, identificadorPerfilado, numFila){

    var aplicacionAuxM = identificadorPerfilado.split("_")[0];
    var codigoPerfilAuxM = identificadorPerfilado.split("_")[1];
    var codigoIdiomaAuxM = identificadorPerfilado.split("_")[2];;
    
    var tableName= "tablaParameters_"+identificadorPerfilado;
    t=$('#'+tableName).dataTable();
    
    
    //$('#tablaParameters_'+identificadorPerfilado).dataTable().fnUpdate({id:'1', aplicacion:aplicacionAuxM, perfil:codigoPerfilAuxM, idioma:codigoIdiomaAuxM, nombre:nombreLinkP, valor:valor}, numFila);
    
    //$('#tablaParameters_'+identificadorPerfilado).dataTable().fnUpdate(['1', aplicacionAuxM, codigoPerfilAuxM, codigoIdiomaAuxM, nombreLinkP, valor, 8], numFila);
    

    }
    My table has 7 colums: id, aplicacion, pefil, idioma, nombre, valor, and the icons column. That '8' you see is a random number just to fill that column.

    When I use the first line of the code above, I get on console the message: Cant get the 'nTr' propierty ... (something similar, my browser its in spanish.)
    When I use the second line, I get a pop-up advise onde browser that sais:
    "datatables warning (table id = 'tableParameters_1_DEFAULT_es'): requested unknown parameter 'id' from the datasource for row2"

    More information, numFila = nRowString, the variable I got when I created the row.

    I think that my problem it's just the way I write the code, something its missing.

    I don´t know if that will be usefull, but this line for adding a row to a dataTable its working for me:

    $('#tablaParameters_'+identificadorPerfilado).dataTable().fnAddData({id:'1', aplicacion:aplicacionAux, perfil:codigoPerfilAux, idioma:codigoIdiomaAux, nombre:nombreLinkP, valor:valor, data:'8'});

    Sorry for such a long post, i'm kinda desperate, imaging my situation, today, in spain is holyday xDD.

    Thank for any help

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    As I said, there's a lot going on, so hard to advise without seeing the issue. If you can't link to your page, can you see if you can replicate the issue on http://live.datatables.net/

    Colin

  • adrianFerreiraadrianFerreira Posts: 9Questions: 2Answers: 0

    Sorry Colin, my third post was a mistake. I give you all the code I have.

    JS code
    https://gist.github.com/adrianferr/552ee7d9d6caf965be52a82c8fd4ce4f

    JSP Code
    https://gist.github.com/adrianferr/504db25128aea115becc1b808af8f65d

    Well, as i told you before, the problem I have is on js file line 116.

    I dont know the exact way to modify a particular row.
    Any help will be amazing. Thanks a lot.

  • adrianFerreiraadrianFerreira Posts: 9Questions: 2Answers: 0

    I finally got it!!

    This code worked for me:
    $('#tablaParameters_'+identificadorPerfilado).dataTable().fnUpdate({aplicacion:aplicacionAuxM, perfil:codigoPerfilAuxM, idioma:codigoIdiomaAuxM, nombre:nombreLink, valor:valor}, nTrGlobal);

    You can close the post.

This discussion has been closed.