How to update attribute element input text id same with autonumber row datatables ?

How to update attribute element input text id same with autonumber row datatables ?

AddisonAddison Posts: 13Questions: 4Answers: 0

Hello, Please Help Me
I want to update column [PO NO] <input id="cellpono_1">, etc to autonumber like column [NO].
So when I press Enter input element Po No, the table is adding row. The column [NO] is autonumber, If I have 2 row and delete row 1, the [NO] -> 2 is automatic being [NO] -> 1.
What I want to ask? How to update the column [PO NO] <input id="cellpono_2"> to <input id="cellpono_1"> just like column [NO] autonumber ?

Here the link to the page :
http://live.datatables.net/ligoqelu/2/edit

Thank you :smile:

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 5,631Questions: 0Answers: 983

    Hi @Addison ,

    I just took a look, and it seems to me that it is incrementing the IDs - I'm seeing

    <input type="text" value="123456789" class="cellpoNo" name="cellpoNo_3" id="cellpoNo_3" readonly="true">
    

    Can you give a step by step instructions on how to reproduce your issue, please.

    Cheers,

    Colin

  • AddisonAddison Posts: 13Questions: 4Answers: 0
    edited May 16

    Yes, Thank you @colin, For example:
    1. If I make two rows with twice enter in input element PO NO. will create NO. 1 - cellpoNo_1 , NO. 2 - cellpoNo_2
    2. Then I delete row id NO. 1 - cellpoNo_1
    3. Now my row id with NO. 2 - cellpoNo_2 change to NO. 1 - cellpoNo_2
    The issue:
    I want when I delete NO. 1 - cellpoNo_1 then :
    row id with NO. 2 - cellpoNo_2 change to NO. 1 - cellpoNo_1
    So number in [NO] and cellpoNo is same after I delete other row.

  • colincolin Posts: 5,631Questions: 0Answers: 983
    edited May 20 Answer ✓

    Hi @Addison ,

    You're going to need a bit more logic to do that. Imagine you've got 10 rows, and you delete the first, you'll need to change all of the later rows. To do that, iterate through all the rows with rows().every(), and decrement the contents of each with row().data() for any row that comes after.

    Hope that helps,

    Cheers,

    Colin

  • AddisonAddison Posts: 13Questions: 4Answers: 0
    edited May 20

    Thank you, @colin
    I figured the way with rows().every()
    The result:
    http://live.datatables.net/ligoqelu/4/edit

    Well Done :)

Sign In or Register to comment.