datatable duplicating row with the same data added.

datatable duplicating row with the same data added.

dupers19dupers19 Posts: 11Questions: 3Answers: 0

Hellow. I hope someone can help me.. i have this issue for almost a day. I what i want to do is. i want to add row in the table using table.row.add([]) function. but the problem here is when i add the same data that is added already it duplicates the existing data.. can anyone help me on how to delete that data with the same value before adding it.. im not using table.clear().draw(); because it will erase all the row and redraw it.. what i want is just to delete the row that i selected then re add it.. Thank You if anyone can help me.

Answers

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    So are you trying to add new data or update existing data?

  • dupers19dupers19 Posts: 11Questions: 3Answers: 0

    Im trying to add a new data. bdway i have a solution to my problem but i don't know if it possible to delete a row using the colmn value to determine which row i want to delete.

  • dupers19dupers19 Posts: 11Questions: 3Answers: 0

    or how to determine if that data already exist on the table?..

  • dupers19dupers19 Posts: 11Questions: 3Answers: 0

    I hope you can help me arron..

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    ok so you want to add a new row and delete existing rows if they are the same? Why add them again if they are the same?

  • dupers19dupers19 Posts: 11Questions: 3Answers: 0
    edited May 2015

    Yes. that's what i want. hmmm. just for security reasons.. this is the logic of thw code so that you can understand it arron.. i have this modal that has a list of items.. then a multi selection. of a row. when the user click on a button add. all of the user selected items will be transfered to another table...my problem is here. what if the user forgot something to select so the user will select again a item. what if the user selected the item with the same value or data in the other table. then it duplicates it.. that why i want to delete the existing data and just add it again..

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    why not just set the items as unique and then it will not allow the user to add it again?

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    if you are using a PHP backend simply add ->validator( 'Validate::unique' ), to the field that has the item key.

  • dupers19dupers19 Posts: 11Questions: 3Answers: 0

    what do you mean by a unique item? of course its already a unique item...but how can i validate that the other table has already this item..

  • dupers19dupers19 Posts: 11Questions: 3Answers: 0

    because im trying to pass the data selected from to the other table.. i tried using table.clear just to refresh it. but the problem is its clear all the table and the prevous selected data that already transfered is removed..

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    I'm guessing you are passing an id field from one table to the other correct? If so on the destination table make that id field require unique values.

  • dupers19dupers19 Posts: 11Questions: 3Answers: 0

    Yes that's correct. but how can i make a validation in datatable?.. any idea?

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0
    edited May 2015

    if you are using php you put

    Field::inst('something')
    ->validator( 'Validate::unique' ),

This discussion has been closed.