Find Duplicates in HTML Table
If someone uses dataTable plugin, can use the following method to find out the duplicate records while adding new record or you can try this code before saving the data
function findInTable(str, tableID){findInTable('your_text', 'put_your_table_id'); // <table id="put_your_table_id">...</table>
$('#' + tableID + ' tr').each(function(){
$(this).children('td').each(function(){
if ( $(this).html() == str ){
alert('Duplicate Records found. ');
return false;
}
}); //end of td each...
}); //end of tr each...
} //end of function..
Call this function where you want to apply and enjoy!
You can use a tag as boolean datatype to prevent adding duplicate record means if it found the data that already exists in the table then it shows a message that "Duplicate Records Can Not Be Inserted." otherwise it would add a new record into the table.
Example: In below example I have written the code directly without using a function and it works fine.
Example: In below example I have written the code directly without using a function and it works fine.
var dup = false;Try this code if you get any issue just feel free to comment here or if you have good example for this code then just write here for helping the people. thanks!
$('#TableId tr').each(function(e){
$(this).children('td').each(function(){
if ( $(this).html() == $('#textbox').val() ){
alert('Duplicate Records Can Not Be Inserted.');
dup = true;
return false;
}
});
}); //end dup checking
if(dup === false){
//Execute your code here
}//end of duplicate checking...
Find Duplicates in HTML Table
Reviewed by Ashok Sen
on
13:35:00
Rating:
No comments:
Post a Comment