No se puede actualizar la celda correcta al orderna o filtrar

No se puede actualizar la celda correcta al orderna o filtrar

jlss070893jlss070893 Posts: 7Questions: 2Answers: 0

Hello everyone, first of all excuse my English if it is not very understandable. My topic is the following I have generated a table with ajax and this great plugin and everything works normally. My topic is as follows when I need to update any value of a cell in table first I get its row with
"var row = table.column (4) .data (). indexOf (parseInt (value))" and I set it with "table.cell(row, 3).data('update').draw()" ** and it works Wonderfully, the problem is when the table is filtered or ordered, the value row changes and the row variable gets the new position correctly, but when setting the **"table.cell(row, 3).data ('update').draw()" updates in the original position of the array and does not take into account that when sorting or filtering the value to modify changes position, has it happened to someone else?, Thanks in advance.

This question has an accepted answers - jump to answer

Answers

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

    It's working as expected here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • jlss070893jlss070893 Posts: 7Questions: 2Answers: 0

    Hi, thanks for the prompt reply, it actually works fine for me when the data in the table is sorted in the same way as the data obtained from the backend, but my problem is when I change the order of the data in the table, huh updated your example to how I work with datatables and maybe I'm wrong about something. For example, with table.column(0).data().IndexOf('Ashton Cox') I look for the name "Ashton Cox" in column 0 which brings me the row correctly which is row 1 but when configuring it in the table.cell(f, 1).data ('CCC Technical Author').draw() to edit the position, if you see in the table edit the position of the name "Garrett Winters" which in the html data is the found in row 1.

    Updated example: live.datatables.net/jocoyogu/3/edit

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    Ah, I see, you need to use eq() for that - see updated example here. There's discussion on that issue here,

    Colin

  • jlss070893jlss070893 Posts: 7Questions: 2Answers: 0
    edited November 2020

    Hello Colin, sorry to bother you again, but I have the following case, the previous problem was solved correctly with cell(':eq()') but now I have the detail that I only obtain the data of the rows of the current page, it is Say the following rows in the following pages only get undefined, I have come to think that it can happen because the table is created dynamically but maybe something is wrong in my code, I leave you an example here: live.datatables.net/culewifu/4/edit , thank you.

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

    Thanks for the test, but I'm not sure what I'm looking at. Please could you get step-by-step instructions on how to reproduce the issue, and also say what would you expect to happen at that point,

    Colin

  • jlss070893jlss070893 Posts: 7Questions: 2Answers: 0
    edited November 2020

    Of course I explain you better. I have a dynamic table created with jquery and ajax and what I want to do is get the data of a cell by means of the cell (':eq' ('+ row +') ', col) method of Datatables. The table is initialized in a normal way but it seems that there is a detail when obtaining the data with the cell() method, it only obtains the data from the current page and not from the following pages, which only obtain undefined, from what I come to think That detail may be happening because the html of the table has been created dynamically since I have done the test in another table that is not dynamic and works normally, one more clarification this only happens on the first page but if I go to the second page and I press the send button, it obtains all the data correctly and if after going to the second page I return to the first page and press the button again, it also obtains correctly, which leads me to think that the problem may be that of somehow it doesn't detect the html of the table on the second page the first time the table is created or something like that, I really don't know if I'm correct.

    Now I explain my example of the link better:

    I have simplified it a bit by removing unnecessary things but I try to replicate it as closely as my code: live.datatables.net/culewifu/5/edit .

    I start by setting the method crearTabla() in the document.ready creating a dynamic table called dt_AlmacenRemoto with jquery and ajax, in this case I am representing the ajax data with the two global arrays arrHeaderUsuario and listaAlmacen that it's the same as I get from the backend. Through those two previous arrays I fill two other global arrays with the necessary data that I will use to initialize datatables and those are the global array arrFinalRe used to set the data in the data option of datatables data: arrFinalRe and the array arrFinalColRe used to set the data of the columnDefs option of Datatables columnDefs: arrFinalColRe. Finally to initialize the table I do it with the list() method and everything works fine, the table initializes correctly. Now the detail is in the enviarProductos method which is where I want to get the data from the cells with the cell (':eq(' + w + ')', 0).data() method and if it gets the data but only of the current page since the data obtained from the following pages is shown as undefined you can see it in the browser console by clicking on the Send button, I hope you understand, thank you.

This discussion has been closed.