row update "misaligned" - single character in a cell

row update "misaligned" - single character in a cell

mhjamhja Posts: 12Questions: 5Answers: 0

Hi,

Before changing a row it looks like this

After updating the row it looks like this

Row data before update look like this

Row data that it is to be change to looks like this

I fetch the row number via: row = $('#myTable').DataTable().row($(this).parents('tr')).index();

I use this to provide the update: $('#myTable').DataTable().row(row).data(d).draw();

Why is each cell just getting a single character?

Kind regards,
Mikael

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Happy to have a look at a test case showing the issue.

    Allan

  • mhjamhja Posts: 12Questions: 5Answers: 0
    edited May 2023

    Hi, sorry for late replay due to vacation.

    Have created a test version, where simulated update is done by closing pop-up. Pop-up is triggered by clicking on the button.
    https://mikago.net/test/produkter_visa_test.php

    function where check for modification and update table row looks like this

    this is the function for row update

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi Mikael,

    No worries - hope you had a nice holiday.

    Thanks for the update. The issue is that d is a string. If you want to update a single cell, then use cell().data(), but it looks like you want to update a full row, so you need to pass in an array of data (since your table is configured for array data sources).

    You could do that like this:

    d = [];
    
    d.push( '<button id="popup-button">' + data.id + '</button><a href="https://quickbutik.com/admin/products/edit/' + data.id + ' target="_blank">' + data.id + '</a>' );
    d.push( data.headcategory_name );
    d.push( 'Test' );
    ....
    

    or

    d = [
      '<button id="popup-button">' + data.id + '</button><a href="https://quickbutik.com/admin/products/edit/' + data.id + ' target="_blank">' + data.id + '</a>',
      data.headcategory_name, 
      'Test',
      ...
    ];
    

    They are functionally the same. After that your row().data() call will work okay.

    Allan

  • mhjamhja Posts: 12Questions: 5Answers: 0

    Now it is working.
    Many thanks. :)

  • mhjamhja Posts: 12Questions: 5Answers: 0
    edited May 2023

    Hi again,
    The row update is working, but when testing the print out function (link for GTIN) it does not work after updating the row - then it just pops up the row content.

    When looking at the "show content" it looks the same and also in "inspect".

    Any clue what that can relate to?

  • mhjamhja Posts: 12Questions: 5Answers: 0

    Managed to fix it with a work-around, adding a second print function after row update that then disables the initial print function.

Sign In or Register to comment.