jQuery check if column contains certain value
Hello friends as we use jquery for client side functionality and we need tables to show the data in tabular form. I had a requirement to to add items to a jquery datatable based on search result. If user already added searched result it doesn’t allow user to add again.
I get the solution by using below code.
$("#table tr td:nth-child(8)").each(function () { var texttocheck = this.innerText.trim(); if (texttocheck == "mukesh") { var errMsg = "user already exists in the list"; alert(errMsg); return false; } return false; });
In the above code I am getting the table child column 8th and then comparing the value, if that value exist it would show error message already exist.
happy coding..
Thank you.
In the meantime I use another approach for the column that has the index 0 :
table.columns([0]).every( function ( colIdx ) {
this.column( colIdx ).data().unique().sort().each( function ( d, j ) {
if(d!=null && $(d).text() == ‘My value’){
}
});
});