Top Ad unit 728 × 90

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){
         $('#' + tableID + ' tr').each(function(){
                       if ( $(this).html() == str ){
                               alert('Duplicate Records found. ');
                               return false;
                 }); //end of td each...
         }); //end of tr each...
} //end of function..
 findInTable('your_text', 'put_your_table_id'); // <table id="put_your_table_id">...</table>

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.

            var dup = false;
            $('#TableId tr').each(function(e){
                           if ( $(this).html() == $('#textbox').val() ){
Duplicate Records Can Not Be Inserted.');
                                 dup = true;
                                 return false;

            });  //end dup checking

            if(dup === false){
                      //Execute your code here
            }//end of duplicate checking...
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!
Find Duplicates in HTML Table Reviewed by Ashok Sen on 13:35:00 Rating: 5

No comments:

Thanks for sharing your valuable comments.

All Rights Reserved by ASENwebmedia © 2014 - 2015
Powered By Blogger, Developed by Asenwebmedia

Contact Form


Email *

Message *

Powered by Blogger.