You must Sign In to post a response.
  • Category: JavaScript

    How to skip row without data and validate only row containing data

    hi all
    what i want is i have one button addnewrow if i click on it it will add row one by one so some rows may contain data some may not so when i click on save button only the validation shoulb be done for rows containing data others should be skipped and data should be saved in db

    this is my function so what to do give me some idea
    function validateIncome(){
    var flgSave = false;
    var flgIsEdit = false;
    var RowCnt=0;
    var VaildRowCnt=0;
    $("#incomeGridB >tbody >tr").each(function () {
    var tr = $(this);
    var displayMode = tr.find("td > label").css("display");
    if (displayMode == 'inline-block' || displayMode == 'block') {
    RowCnt ++;
    flgIsEdit = true;
    if(tr.find("#customer").val()=="Select"){
    displayAlert("Please select the customer.");
    return false;
    }
    if(tr.find("#plnContract").val()=="Select"){
    displayAlert("Please select the contract status.");
    return false;
    }
    if(tr.find("#plnContractNo").val().trim()==""){
    displayAlert("Please enter the contract number.");
    return false;
    }
    if(tr.find("#strtMnth").val()=="Select"){
    displayAlert("Please select the start month.");
    return;
    }
    if(tr.find("#endMnth").val()=="Select"){
    displayAlert("Please select the end month.");
    return false;
    }
    if(tr.find("#endMnth").prop('selectedIndex')<tr.find("#strtMnth").prop('selectedIndex')){
    displayAlert("End month should be greater than start month.");
    return false;
    }
    var flgMonthValPresent = false;
    for(var i=1;i<=12;i++){
    if(tr.find("#month"+i).val().trim()!=""){
    flgMonthValPresent = true;
    }
    }
    if(!flgMonthValPresent){
    displayAlert("Please enter the amount for atleast one month.");
    return false;
    }
    VaildRowCnt++;
    }
    });
    if(RowCnt==VaildRowCnt){
    flgSave = true;
    }
    if(toDelete.length>0 && flgIsEdit==false){
    flgSave = true;
    flgIsEdit = true;
    }
    if(!flgIsEdit){
    displayAlert("There is no data entered/modified to save.");
    flgSave = false;
    }
    return flgSave;
    }
  • #768322

    Hi,

    In your coding you have used IF conditions to sort out the row which are empty or null
    Using Enumeration we can simply do this. This technique in Enumeration is very simple and effective.


    foreach(var column in table.Columns.Cast<DataColumn>().ToArray()) {
    if (table.AsEnumerable().All(dr => dr.IsNull(column)))
    table.Columns.Remove(column);
    }


    This Foreach will traverse around all the values in the datatable and remove all the null or empty rows which are present in the datagrid or datatable.


    Thanks,
    Mani


  • Sign In to post your comments