Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
702 views
in Technique[技术] by (71.8m points)

jquery - Uncheck table row in bootstrap table on specific condition

My previous question was this and I want to uncheck checked row if user selects a row that has 'Stock Available=null or 0'. Now my jquery code is:

$(document).ready(function()
{
    $("#add_cart_btn").hide();
    var json;
    var checkedRows = [];
    $('#table-style').on('check.bs.table', function (e, row) {
      checkedRows.push({id: row.id});
      $("#add_cart_btn").show();
    });

    $('#table-style').on('uncheck.bs.table', function (e, row) {
      $.each(checkedRows, function(index, value) {
        if (value.id === row.id) {
          checkedRows.splice(index,1);
        }
      });
    });
     /*if(checkedRows.length < 0) {
        // does not exist
        $("#add_cart_btn").hide();
      }
      else {
        // does exist
        $("#add_cart_btn").show();
      }*/

});

Here I'm also trying to show $("#add_cart_btn") button iff checkedRows[] contains at least one record. I searched bootstrap events for above but can not understood it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

About to uncheck the Row if is it has 'Stock Available=null or 0, I assume that you are using the bootstrap-table by wenzhixin and that your data has a unique id like you mentioned row.id in your question

My Approach goes like this: 1. Define a unique ID of your table when you are loading the Data 2. oncheck : use row to check if the Stock_Available is null or 0 3. if Yes use the method

$("#table").bootstrapTable("uncheckBy", { field: "Stock_Available", values: [row.id] })

Here is the solution http://jsfiddle.net/pacitwizere/xjvp8xq0/5/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...