datatable duplicating row with the same data added.
datatable duplicating row with the same data added.
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
So are you trying to add new data or update existing data?
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.
or how to determine if that data already exist on the table?..
I hope you can help me arron..
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?
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..
why not just set the items as unique and then it will not allow the user to add it again?
if you are using a PHP backend simply add ->validator( 'Validate::unique' ), to the field that has the item key.
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..
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..
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.
Yes that's correct. but how can i make a validation in datatable?.. any idea?
if you are using php you put
Field::inst('something')
->validator( 'Validate::unique' ),