Hamza Shah

Hamza Shah

  • NA
  • 87
  • 22.8k

The system show error message in the same grid at the end (last column

Mar 1 2021 6:00 AM
I've working on a project where I'm importing customers data from .Csv file and then after reading the file load data in a grid (HTML table). I've set some checks on the values if there format are wrong so then it's shows error at the end column of table. Now I Want If a file is not validated, the system should show error messages in the same grid at the end (last column). In this case show a prompt to the user "There is some error in data, please check the last column of the grid for further detail" So how can I do that?
 
Here I'm loading the data in a grid and validating it.
  1. var NoOfColumn = FileDataArray[0].length;  
  2. $("tbody").empty();  
  3. for (var i = 0; i < FileDataArray.length; i++)  
  4. {  
  5. var tr = "<tr>"  
  6. $.each(FileDataArray[i], function (i, v) {  
  7. tr = tr + "<td>" + v + "</td>";  
  8. })  
  9. tr = tr + "</tr>";  
  10. $("tbody").append(tr);  
  11. }  
  12. var cntrl = $("#dialog-ProductLoader-div");  
  13. cntrl.dialog("close");  
  14. for (var i = 0; i < FileDataArray.length; i++)  
  15. {  
  16. if (i != 0) {  
  17. for (var j = 0; j < FileDataArray[i].length; j++) {  
  18. if (FileDataArray[i][0] == null && j == 0)  
  19. alert("Customer Name is Mandatory");  
  20. if (FileDataArray[i][1] == null && j == 1) {  
  21. alert("Customer Type Name Input is mandatory");  
  22. }  
  23. if (FileDataArray[i][2] == null || FileDataArray[i][2] == "No" && j == 2) {  
  24. FileDataArray[i][2] == false;  
  25. }  
  26. if (FileDataArray[i][2] == "Yes" || "yes" && j == 2) {  
  27. FileDataArray[i][2] == true;  
  28. }  
  29. if (FileDataArray[i][3] == null && j == 3) {  
  30. FileDataArray[i][3] == 0;  
  31. }  
  32. if (isNaN(FileDataArray[i][3]) && j == 3) {  
  33. alert("Credit Limit value must be numeric")  
  34. }  
  35. if (FileDataArray[i][4] == null && j == 4) {  
  36. FileDataArray[i][4] == 0;  
  37. }  
  38. if (isNaN(FileDataArray[i][4]) && j == 4) {  
  39. alert("Opening Balance value must be numeric")  
  40. }  
  41. if (FileDataArray[i][5] != ("Male" || "male" || "female" || "Female" || "other" || "Other" || "") && j == 5) {  
  42. alert("Error");  
  43. }  
  44. if (isDate(FileDataArray[i][6]) && j == 6) {  
  45. alert("Error")  
  46. }  
  47. if (isDate(FileDataArray[i][7]) && j == 7) {  
  48. alert("Error")  
  49. }  
  50. var mailformat = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;  
  51. if((!mailformat.test(FileDataArray[i][9]) && j == 9)){  
  52. alert("Email is invalid")  
  53. }  
  54. }  
  55. }  
  56. }  
And Here is View
  1. <div class="customertable">  
  2. <table class="table table-bordered table-responsive">  
  3. <thead class="thead-light">  
  4. <tr>  
  5.   
  6. </tr>  
  7. </thead>  
  8. <tbody id="loaderBody">  
  9. </tbody>  
  10. </table>  
  11. </div>