mardi 7 août 2018

how to hide datatable rows where code is have "." e.g 1.1, 1.2 through jquery?

I take data of two inputs to another page through ajax. I used these two values in query and shown the result of selectquery in a datatable which is return back to success function and shown in table at mainpage. After that i want to use condition that data with "."(accounting->subaccounts) hide unless He click a button. i just need idea to hide it i can do more. let me show you my code.

This is the button:

<input type="button" id="generate" onclick="getData();" value="Generate"  
class="btn btn-block btn-primary btn-sm" />

The div where i shown the table:

<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12" id="tab"></div>

the ajax function:

function getData() {
            var date = $("#date").val();
            var classId = $("#class").val();
            $.ajax({
                url: "ajax/getTrailBalanceData.php",
                type: "POST",
                data: {
                    "date": date,
                    "classId": classId,
                },
                cache: false,
                async: false,
                success: function (data) {
        //alert(data);                  
                    $("#tab").html(data);

                    var row_main_code = $("#main_code").val();


                    if (row_main_code.indexOf(".") > -1) {
    //                  $("#tbl_row").addClass("hide");
                    } else {
  //                      $("#tbl_row").removeClass("hide");
 //                    $("#main_code").parents("tr").hide();
 //                    $("#tbl_row").addClass("hide");
      //                 $("#main_code").val("hide");
                    }
                }
            });
        }

The if(rowmaincode.indexof('.')>-1) condition in "success" i tried but not give desirable result i am confused i dont know why but let me show you the other page code:

<table id="trail_balance_list" class="table table-bordered table-condensed bootstrap-datatable datatable responsive">
<thead id="table_head">
    <tr class="bg-success">

        <th class=" text-center">Code</th>
        <th class=" text-center">Account Title</th>
        <th class=" text-center" >Debit</th>
        <th class=" text-center" >Credit</th>
        <th class=" text-center" >Action</th>

    </tr>
</thead>
<tbody>
    <?php
    while ($row = mysqli_fetch_assoc($result)) {
        ?>
    <tr  id="tbl_row" class="">
            <td><?php echo $row['main_code']; ?><input type="hidden" id="main_code" value="<?php echo $row['main_code']; ?>" /></td>
            <td><?php echo $row['account_title']; ?></td>
            <td></td>
            <td></td>
            <td class="text-center"><button class="btn btn-info"><i class="fa fa-arrow-down"></i></button></td>
        </tr>
        <?php
    }
    ?>
</tbody>
<tfoot>
    <tr>
        <th><input type="hidden" id="total_credit_input" name="total_credit" value="0" /></th>
        <th><input type="hidden" id="total_debit_input" name="total_debit" value="0" /></th>
        <td class="bg-warning text-center" id="total_debit">0.00</td>
        <td class="bg-warning text-center" id="total_credit" >0.00</td>

    </tr>
</tfoot>
</table>
<script>
   $(document).ready(function () {
        $("#trail_balance_list").dataTable();
   });
</script>

the result i get is like : see image i want show only like 1,2,3,4

Aucun commentaire:

Enregistrer un commentaire