mardi 15 juin 2021

Display the checkboxes in the console using java

I have many pdf files and I need to extract the entire test from those files and display it in the console. I can do that easily using PDF box and I was able to print that in console. But some files have many checkboxes for e.g it displays frequency: []1year []monthly []3 years like this way and one of the boxes is crossed(checked). But the problem is in console its showing like this: frequency: 1year monthly 3years the checkboxes are not getting printed. I have searched everywhere and all are showing how to create a checkbox but I dont need that. I just want to display it and then I have to find out what is the frequency. How to do that? Given here is my code to extract pdf data:-

PDDocument doc=PDDocument.load(file);

PDTextStripper pdfStripper=new PDTextStripper();

String text=pdStripper.getText(doc);

System.out.println(text);




Check if the codes are in array then make then checked else unchecked

I have a query. The code is working perfectly in the fiddle. But it is not working in my application so I am confused why?

If you run the snippet and check the checkbox against CRL, it will basically add the codes of attachements attached in the attachment heading to array. Now I am checking whether those codes are in the array if yes then make them checked. Somehow this is not working in my application. but is working in snippet. Please help as to what it could be causing.

The line of code that is not working is this

  $(`#attchment_div 
input[id=chkAttachment_${docCodes[i]}]`).prop("checked", true)

I have tried other formats like

$("#attchment_div #AttachmentGrid").find(".attachment_selection").find('input[id=chkAttachment_${docCodes[i]}]').attr("checked", true);

or

$("#attchment_div #AttachmentGrid").find('input[id=chkAttachment_${docCodes[i]}]').attr("checked", true);

//on change of checkbox inside table..
$(document).on("change", "#AttachmentGrid .attachment_selection", function() {

  var total = $(".attachment_selection").length
  var get_code = $("#AttachmentGrid").data("code").split("_")[1]
  //if all checked..
  if ($(".attachment_selection:checked").length == total) {
    $("#uploadGrid tr[cdCode=" + get_code + "]").find("input:checkbox").prop("checked", true)
  } else {
    $("#uploadGrid tr[cdCode=" + get_code + "]").find("input:checkbox").prop("checked", false)
  }

})
var docCodes = [];

function AttchmentBox(id, count, el) {

  if (parseInt(count) > 0) {

    $("#attchment_div #AttachmentGrid").find(".attachment_selection").prop("checked", false)
    var data_codes = $(el).closest("tr").find(".activity_selection").data("code").split(",")
    console.log(data_codes)
    if ($(el).closest("tr").find(".activity_selection").is(":checked")) {
      //check if any datacodes.. present in array
      var found = false;
      for (var i = 0; i < docCodes.length; i++) {
        if (docCodes.indexOf(data_codes[i]) > -1) {
          found = true;
          break;
        }
      }
      //if prsent
      if (found) {
        //show slected data only...
        $(docCodes).each(function(i) {
          if (docCodes.indexOf(data_codes[i]) != -1) {
            $(`#attchment_div input[id=chkAttachment_${docCodes[i]}]`).prop("checked", true)
          }
        })
      } else {
        //show all selected
        $("#attchment_div #AttachmentGrid").find(".attachment_selection").prop("checked", true)
      }

    } else {
      //show selected data,,,bcuz checkbox(snoe) is unchecked
      $(docCodes).each(function(i) {
        if (docCodes.indexOf(data_codes[i]) != -1) {
          $(`#attchment_div input[id=chkAttachment_${docCodes[i]}]`).prop("checked", true)
        }
      })


    }
    //sno is checked call your function: 
    addAttributes()
    $("#attchment_div #AttachmentGrid").data("code", id)
    $("#attchment_div").show()
  }

}


function addAttributes(docID, CdCode, el) {
  //el == undefined call from AttchmentBox
  if (el == undefined) {
    //loop through checked checkbox...
    $(".attachment_selection:checked").each(function() {
      var str = $(this).attr("id").split("_")[1]; //id=chkAttachment_78424 .etc
      //if not inside array
      if (docCodes.indexOf(str) == -1) {
        docCodes.push(str) //push that in array
      }
    })

  } else {
    var str = docID;
    //if checked..and not inside array
    if ($(el).is(':checked') && docCodes.indexOf(str) == -1) {
      docCodes.push(str)
    } else {
      docCodes.splice(docCodes.indexOf(str), 1) //remove it..
    }
  }
  console.log(docCodes.toString())
}

//on change of table checkboxes
function addAttr(el) {
  var data_attr = $(el).data("code").split(",")
  if ($(el).is(":checked")) {
    $(data_attr).each(function(i) {
      if (docCodes.indexOf(data_attr[i]) == -1) {
        docCodes.push(data_attr[i]) //push that in array
      }
    })
  } else {

    $(data_attr).each(function(i) {
      docCodes.splice(docCodes.indexOf(data_attr[i]), 1)
    })

  }
  console.log(docCodes.toString())


}

$('#selectAll').on('click', function(e) {
  checkAllBox(this, 'activity_selection');
})

function checkAllBox(obj, clsName) {

  if (obj.checked) { // check select status
    $('.' + clsName).each(function() {
      this.checked = true;
      var data_attr = $(this).attr("data-code").split(",")
      $(data_attr).each(function(i) {
        if (docCodes.indexOf(data_attr[i]) == -1) {
          docCodes.push(data_attr[i]) //push that in array
        }
      })


    });
  } else {
    $('.' + clsName).each(function() {
      this.checked = false;
      var data_attr = $(this).attr("data-code").split(",")
      $(data_attr).each(function(i) {
        docCodes.splice(docCodes.indexOf(data_attr[i]), 1)
      })
    });
  }
  console.log(docCodes.toString())
}
#attchment_div {
  display: none;
  border: 1px solid black
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>


<table id="uploadGrid" class="display" width="100%">
  <thead>
    <tr>
      <th class="Greyheader"><input id="selectAll" type="checkbox" /> <br />S.No</th>
      <th class="Greyheader">Document Name</th>
      <th class="Greyheader">Browse</th>
      <th class="Greyheader">Attachment</th>
      <th class="Greyheader">Save</th>
    </tr>
  </thead>
  <tbody>
    <tr id="517">
      <td class="GreyBorder">1&nbsp;&nbsp;<input id="chk_517" class="activity_selection" type="checkbox" data-code="78424,78427" /></td>
      <td class="GreyBorder">CRL</td>
      <td class="GreyBorder" style="text-align: center !important;"><input id="txt_filePath_517" class="mediumTextField" style="width: 78%;" multiple="multiple" name="txt_filePath_517" type="file" /></td>
      <td class="GreyBorder" style="text-align: center !important;" align="center"><span style="cursor: hand;"><span class="attch_counter">3</span><img class="AttachmentBox" title="Attachment" onclick="AttchmentBox('_41701','2',this);" src="../../Images/attchments.png" height="20px" /></span>
      </td>
      <td class="GreyBorder" align="center"><img id="Btn_517" class="AddItem" style="cursor: pointer; height: 15px;" title="Save" src="../../Images/save.png" /></td>


  </tbody>
</table>


<div id="attchment_div">
  <table style="width:100%" id="AttachmentGrid">
    <tr>
      <td style="text-align:left; width:40%;">
        <input type='checkbox' id=chkAttachment_78427 class='attachment_selection' onclick="addAttributes('78427','41701',this);">
        <a title="ABC.docx" onclick="showDocument('78427');" style='text-decoration: none;cursor: pointer;'>
          <div class='ui-notify-message ui-notify-message-style'>
            <div style='float:left;margin:0 10px 0 0' class='image_path'>
              <img src='../../Images/attchments.png'>
            </div>
            <p>ABC.docx</p>
          </div>
        </a>
      </td>
      <td style="text-align:center; width:35%;">
        <div style='float:left;position:relative;top:-6px;'>
          <div class='date'>
            <span class='day'>10</span>
            <span class='month'>Jun</span>
            <span class='year'>2021</span>
          </div>
        </div>
      </td>
      <td style="width:20%; cursor:hand;">
        <img viewtype="delete" title="Delete Attachment" style="float:right;padding-bottom:20px;" src="../../images/delete.png" onclick="DeleteAttachment('78427','41701')" class="AddItem" />
      </td>
    </tr>
    <tr>
      <td style="text-align:left; width:40%;">
        <input type='checkbox' id=chkAttachment_78424 class='attachment_selection' onclick="addAttributes('78424','41701',this);">
        <a title="FOSUNDERSTANDING.docx" onclick="showDocument('78424');" style='text-decoration: none;cursor: pointer;'>
          <div class='ui-notify-message ui-notify-message-style'>
            <div style='float:left;margin:0 10px 0 0' class='image_path'>
              <img src='../../Images/attchments.png' />
            </div>
            <p>FOSUNDERSTANDING.docx</p>
          </div>
        </a>
      </td>
      <td style="text-align:center; width:35%;">
        <div style='float:left;position:relative;top:-6px;'>
          <div class='date'>
            <span class='day'>09</span>
            <span class='month'>Jun</span>
            <span class='year'>2021</span>
          </div>
        </div>
      </td>
      <td style="width:20%; cursor:hand;">
        <img viewtype="delete" title="Delete Attachment" style="float:right;padding-bottom:20px;" src="../../images/delete.png" onclick="DeleteAttachment('78424','41701')" class="AddItem" />
      </td>
    </tr>
  </table>
</div>
<div id="attchment_div">
  <table style="width:100%" id="AttachmentGrid">
    <tr>
      <td style="text-align:left; width:40%;">
        <input type='checkbox' id=chkAttachment_78427 class='attachment_selection' onclick="addAttributes('78427','41701',this);">
        <a title="ABC.docx" onclick="showDocument('78427');" style='text-decoration: none;cursor: pointer;'>
          <div class='ui-notify-message ui-notify-message-style'>
            <div style='float:left;margin:0 10px 0 0' class='image_path'>
              <img src='../../Images/attchments.png'>
            </div>
            <p>ABC.docx</p>
          </div>
        </a>
      </td>
      <td style="text-align:center; width:35%;">
        <div style='float:left;position:relative;top:-6px;'>
          <div class='date'>
            <span class='day'>10</span>
            <span class='month'>Jun</span>
            <span class='year'>2021</span>
          </div>
        </div>
      </td>
      <td style="width:20%; cursor:hand;">
        <img viewtype="delete" title="Delete Attachment" style="float:right;padding-bottom:20px;" src="../../images/delete.png" onclick="DeleteAttachment('78427','41701')" class="AddItem" />
      </td>
    </tr>
    <tr>
      <td style="text-align:left; width:40%;">
        <input type='checkbox' id=chkAttachment_78424 class='attachment_selection' onclick="addAttributes('78424','41701',this);">
        <a title="FOSUNDERSTANDING.docx" onclick="showDocument('78424');" style='text-decoration: none;cursor: pointer;'>
          <div class='ui-notify-message ui-notify-message-style'>
            <div style='float:left;margin:0 10px 0 0' class='image_path'>
              <img src='../../Images/attchments.png' />
            </div>
            <p>FOSUNDERSTANDING.docx</p>
          </div>
        </a>
      </td>
      <td style="text-align:center; width:35%;">
        <div style='float:left;position:relative;top:-6px;'>
          <div class='date'>
            <span class='day'>09</span>
            <span class='month'>Jun</span>
            <span class='year'>2021</span>
          </div>
        </div>
      </td>
      <td style="width:20%; cursor:hand;">
        <img viewtype="delete" title="Delete Attachment" style="float:right;padding-bottom:20px;" src="../../images/delete.png" onclick="DeleteAttachment('78424','41701')" class="AddItem" />
      </td>
    </tr>
  </table>
</div>



lundi 14 juin 2021

How to synchronise ExtJS "checkboxes" (buttons) with Javascript/JQuery?

I am currently trying to synchronise two checkboxes on a page.

I need the checkboxes to be synchronised - to this end I'm using a Tampermonkey userscript to pick up when one of them is clicked. However, I'm at a loss as to how to do it.

I believe they are not actually checkboxes, but ExtJS buttons that resemble checkboxes. I can't check whether they're checked with JQuery because of this: the checked value is appended to a class once the JS behind the button has run.

I have tried preventDefault and stopPropagation, but either I'm using it wrong or not understanding its' usage.

I'm not quite clever enough to just call the JS behind the box instead of an onclick event, otherwise that would solve my issue.

This is my code:

//Variables - "inputEl" is the actual button.
var srcFFR = "checkbox-1097";
var destFFR = "checkbox-1134";
var srcFFRb = "checkbox-1097-inputEl";
var destFFRb = "checkbox-1134-inputEl";

//This checks if they're synchronised on page load and syncs them with no user intervention.
var srcChk = document.getElementById(srcFFR).classList.contains('x-form-cb-checked');
var destChk = document.getElementById(destFFR).classList.contains('x-form-cb-checked');

if (srcChk == true || destChk == false){
    document.getElementById(destFFRb).click();}
else if (destChk == true || srcChk == false) {
    document.getElementById(srcFFRb).click();}

//This is where it listens for the click and attempts to synchronise the buttons.

   $(document.getElementById(srcFFRb)).on('click',function(e){
        e.preventDefault();
        if (document.getElementById(srcFFR).classList == document.getElementById(destFFR).classList) {
            return false;}
        else {
            document.getElementById(destFFRb).click();}});

    $(document.getElementById(destFFRb)).on('click',function(e){
        e.preventDefault();
        if (document.getElementById(srcFFR).classList == document.getElementById(destFFR).classList) {
            return false;}
        else {
            document.getElementById(srcFFRb).click();
        }});

I'm at a bit of a loss...any help would be greatly appreciated.




How to check if the user unchecks a checkbox and remain unchecked even when the dialog box is open

I have this little query.

The problem is when I click on No 1 checkbox(CRL) and then click on the attachment image in the same row, All the checkboxes inside that dialog box will get checked.

Now suppose I unchecked one checkbox say : Book1.xlxs and then close the dialog and open the dialoag again, all checkboxes will be checked again.

Is there any way if the user unchecks it then it should remain unchecked, even if he opens or close that dialog box again? Please help.

//on change of checkbox inside table..
$(document).on("change", "#AttachmentGrid .attachment_selection", function() {

  var total = $(".attachment_selection").length
  var get_code = $("#AttachmentGrid").data("code").split("_")[1]
  //if all checked..
  if ($(".attachment_selection:checked").length == total) {
    $("#uploadGrid tr[cdCode=" + get_code + "]").find("input:checkbox").prop("checked", true)
  } else {
    $("#uploadGrid tr[cdCode=" + get_code + "]").find("input:checkbox").prop("checked", false)
  }

})

function AttchmentBox(id, count, el) {

  if (parseInt(count) > 0) {

    $("#attchment_div #AttachmentGrid").find(".attachment_selection").prop("checked", false)

    if ($(el).closest("tr").find(".activity_selection").is(":checked")) {
      $("#attchment_div #AttachmentGrid").find(".attachment_selection").prop("checked", true)
      //sno is checked call your function: 
      addAttributes()

    }
    $("#attchment_div #AttachmentGrid").data("code", id)
    $("#attchment_div").show()
  }

}
var docCodes = [];

function addAttributes(docID, CdCode, el) {
  //el == undefined call from AttchmentBox
  if (el == undefined) {
    //loop through checked checkbox...
    $(".attachment_selection:checked").each(function() {
      var str = $(this).attr("id").split("_")[1]; //id=chkAttachment_78424 .etc
      //if not inside array
      if (docCodes.indexOf(str) == -1) {
        docCodes.push(str) //push that in array
      }
    })

  } else {
    var str = docID;
    //if checked..and not inside array
    if ($(el).is(':checked') && docCodes.indexOf(str) == -1) {
      docCodes.push(str)
    } else {
      docCodes.splice(docCodes.indexOf(str), 1) //remove it..
    }
  }
  console.log(docCodes.toString())
}

//on change of table checkboxes
function addAttr(el) {
  var data_attr = $(el).data("code").split(",")
  if ($(el).is(":checked")) {
    $(data_attr).each(function(i) {
      if (docCodes.indexOf(data_attr[i]) == -1) {
        docCodes.push(data_attr[i]) //push that in array
      }
    })
  } else {

    $(data_attr).each(function(i) {
      docCodes.splice(docCodes.indexOf(data_attr[i]), 1)
    })

  }
  console.log(docCodes.toString())


}

$('#selectAll').on('click', function(e) {
  checkAllBox(this, 'activity_selection');
})

function checkAllBox(obj, clsName) {

  if (obj.checked) { // check select status
    $('.' + clsName).each(function() {
      this.checked = true;
      var data_attr = $(this).attr("data-code").split(",")
      $(data_attr).each(function(i) {
        if (docCodes.indexOf(data_attr[i]) == -1) {
          docCodes.push(data_attr[i]) //push that in array
        }
      })


    });
  } else {
    $('.' + clsName).each(function() {
      this.checked = false;
      var data_attr = $(this).attr("data-code").split(",")
      $(data_attr).each(function(i) {
        docCodes.splice(docCodes.indexOf(data_attr[i]), 1)
      })
    });
  }
  console.log(docCodes.toString())
}
#attchment_div {
  display: none;
  border: 1px solid black
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>


<table id="uploadGrid" class="display" width="100%">
  <thead>
    <tr>
      <th class="Greyheader"><input id="selectAll" type="checkbox" /> <br />S.No</th>
      <th class="Greyheader">Document Name</th>
      <th class="Greyheader">Browse</th>
      <th class="Greyheader">Attachment</th>
      <th class="Greyheader">Save</th>
    </tr>
  </thead>
  <tbody>
    <tr id="517">
      <td class="GreyBorder">1&nbsp;&nbsp;<input id="chk_517" class="activity_selection" onclick="addAttr(this);" type="checkbox" data-code="78424,78427,78428" /></td>
      <td class="GreyBorder">CRL</td>
      <td class="GreyBorder" style="text-align: center !important;"><input id="txt_filePath_517" class="mediumTextField" style="width: 78%;" multiple="multiple" name="txt_filePath_517" type="file" /></td>
      <td class="GreyBorder" style="text-align: center !important;" align="center"><span style="cursor: hand;"><span class="attch_counter">3</span><img class="AttachmentBox" title="Attachment" onclick="AttchmentBox('_41701','2',this);" src="../../Images/attchments.png" height="20px" /></span>
      </td>
      <td class="GreyBorder" align="center"><img id="Btn_517" class="AddItem" style="cursor: pointer; height: 15px;" title="Save" src="../../Images/save.png" /></td>
    </tr>
    <tr id="518">
      <td class="GreyBorder">2&nbsp;&nbsp;<input id="chk_518" class="activity_selection" onclick="addAttr(this);" type="checkbox" data-code="78426" /></td>
      <td class="GreyBorder">XYZ</td>
      <td class="GreyBorder" style="text-align: center !important;"><input id="txt_filePath_518" class="mediumTextField" style="width: 78%;" multiple="multiple" name="txt_filePath_518" type="file" /></td>
      <td class="GreyBorder" style="text-align: center !important;" align="center"><span style="cursor: hand;"><span class="attch_counter">1</span><img class="AttachmentBox" title="Attachment" src="../../Images/attchments.png" height="20px" /></span>
      </td>
      <td class="GreyBorder" align="center"><img id="Btn_518" class="AddItem" style="cursor: pointer; height: 15px;" title="Save" src="../../Images/save.png" /></td>
    </tr>
    <tr id="519">
      <td class="GreyBorder">3&nbsp;&nbsp;<input id="chk_519" class="activity_selection" onclick="addAttr(this);" type="checkbox" data-code="78429" /></td>
      <td class="GreyBorder">ABC</td>
      <td class="GreyBorder" style="text-align: center !important;"><input id="txt_filePath_519" class="mediumTextField" style="width: 78%;" multiple="multiple" name="txt_filePath_519" type="file" /></td>
      <td class="GreyBorder" style="text-align: center !important;" align="center"><span style="cursor: hand;"><span class="attch_counter">1</span><img class="AttachmentBox" title="Attachment" src="../../Images/attchments.png" height="20px" /></span>
      </td>
      <td class="GreyBorder" align="center"><img id="Btn_519" class="AddItem" style="cursor: pointer; height: 15px;" title="Save" src="../../Images/save.png" /></td>
    </tr>

  </tbody>
</table>


<div id="attchment_div">
  <table id="AttachmentGrid" style="width: 100%;">
    <tbody>
      <tr>
        <td style="text-align: left; width: 40%;"><input id="chkAttachment_78428" class="attachment_selection" type="checkbox" onclick="addAttributes('78428','41701',this);" />
          <div class="ui-notify-message ui-notify-message-style">
            <div class="image_path" style="float: left; margin: 0 10px 0 0;"><img src="../../Images/attchments.png" /></div>
            <p>Book1.xlsx</p>
          </div>
        </td>
        <td style="text-align: center; width: 35%;">
          <div style="float: left; position: relative; top: -6px;">
            <div class="date"><span class="day">11</span> <span class="month">Jun</span> <span class="year">2021</span></div>
          </div>
        </td>
        <td style="width: 20%; cursor: hand;"><img class="AddItem" style="float: right; padding-bottom: 20px;" title="Delete Attachment" src="../../images/delete.png" /></td>
      </tr>
      <tr>
        <td style="text-align: left; width: 40%;"><input id="chkAttachment_78427" class="attachment_selection" type="checkbox" onclick="addAttributes('78428','41701',this);" />
          <div class="ui-notify-message ui-notify-message-style">
            <div class="image_path" style="float: left; margin: 0 10px 0 0;"><img src="../../Images/attchments.png" /></div>
            <p>ABC.docx</p>
          </div>
        </td>
        <td style="text-align: center; width: 35%;">
          <div style="float: left; position: relative; top: -6px;">
            <div class="date"><span class="day">10</span> <span class="month">Jun</span> <span class="year">2021</span></div>
          </div>
        </td>
        <td style="width: 20%; cursor: hand;"><img class="AddItem" style="float: right; padding-bottom: 20px;" title="Delete Attachment" src="../../images/delete.png" /></td>
      </tr>
      <tr>
        <td style="text-align: left; width: 40%;"><input id="chkAttachment_78424" class="attachment_selection" type="checkbox" onclick="addAttributes('78424','41701',this);" />
          <div class="ui-notify-message ui-notify-message-style">
            <div class="image_path" style="float: left; margin: 0 10px 0 0;"><img src="../../Images/attchments.png" /></div>
            <p>FOSUNDERSTANDING.docx</p>
          </div>
        </td>
        <td style="text-align: center; width: 35%;">
          <div style="float: left; position: relative; top: -6px;">
            <div class="date"><span class="day">09</span> <span class="month">Jun</span> <span class="year">2021</span></div>
          </div>
        </td>
        <td style="width: 20%; cursor: hand;"><img class="AddItem" style="float: right; padding-bottom: 20px;" title="Delete Attachment" src="../../images/delete.png" /></td>
      </tr>
    </tbody>
  </table>
</div>



The argument type 'Function' can't be assigned to the parameter type 'void Function(bool?)?'. null object

here is my code and error is after fluttre update to 2.13 version so please help.... error is on TaskCheckBox class onchanged method and dart analys return The argument type 'Function' can't be assigned to the parameter type 'void Function(bool?)?'.

class TaskTile extends StatefulWidget {
  @override
  _TaskTileState createState() => _TaskTileState();
}

class _TaskTileState extends State<TaskTile> {
  bool isChecked = false;

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(
        'This is task.',
        style: TextStyle(
          decoration: isChecked ? TextDecoration.lineThrough : null,
        ),
      ),
      trailing: TaskCheckBox(checkboxState: isChecked,toggleCheckboxState: (bool checkboxState) {
        setState(() {
          isChecked = checkboxState;
        });
      }),
    );
  }
}

class TaskCheckBox extends StatelessWidget {
  final bool checkboxState;
  final Function toggleCheckboxState;

  TaskCheckBox({required this.checkboxState,required this.toggleCheckboxState});

  @override
  Widget build(BuildContext context) {
    return Checkbox(
      activeColor: Colors.lightBlueAccent,
      value: checkboxState,
      onChanged: toggleCheckboxState,
    );
  }
}



How to check if user unchecked checkboxes and keep them unchecked when he opens a box again

I have this little query.

The problem is when I click on No 1 checkbox(CRL) and then click on the attachment image in the same row, All the checkboxes inside that dialog box will get checked.

Now suppose I unchecked one checkbox say : Book1.xlxs and then close the dialog and open the dialoag again, all checkboxes will be checked again.

Is there any way if the user unchecks it then it should remain unchecked, even if he opens or close that dialog box again?

//on change of checkbox inside table..
$(document).on("change", "#AttachmentGrid .attachment_selection", function() {

  var total = $(".attachment_selection").length
  var get_code = $("#AttachmentGrid").data("code").split("_")[1]
  //if all checked..
  if ($(".attachment_selection:checked").length == total) {
    $("#uploadGrid tr[cdCode=" + get_code + "]").find("input:checkbox").prop("checked", true)
  } else {
    $("#uploadGrid tr[cdCode=" + get_code + "]").find("input:checkbox").prop("checked", false)
  }

})

function AttchmentBox(id, count, el) {

  if (parseInt(count) > 0) {

    $("#attchment_div #AttachmentGrid").find(".attachment_selection").prop("checked", false)

    if ($(el).closest("tr").find(".activity_selection").is(":checked")) {
      $("#attchment_div #AttachmentGrid").find(".attachment_selection").prop("checked", true)
      //sno is checked call your function: 
      addAttributes()

    }
    $("#attchment_div #AttachmentGrid").data("code", id)
    $("#attchment_div").show()
  }

}
var docCodes = [];

function addAttributes(docID, CdCode, el) {
  //el == undefined call from AttchmentBox
  if (el == undefined) {
    //loop through checked checkbox...
    $(".attachment_selection:checked").each(function() {
      var str = $(this).attr("id").split("_")[1]; //id=chkAttachment_78424 .etc
      //if not inside array
      if (docCodes.indexOf(str) == -1) {
        docCodes.push(str) //push that in array
      }
    })

  } else {
    var str = docID;
    //if checked..and not inside array
    if ($(el).is(':checked') && docCodes.indexOf(str) == -1) {
      docCodes.push(str)
    } else {
      docCodes.splice(docCodes.indexOf(str), 1) //remove it..
    }
  }
  console.log(docCodes.toString())
}

//on change of table checkboxes
function addAttr(el) {
  var data_attr = $(el).data("code").split(",")
  if ($(el).is(":checked")) {
    $(data_attr).each(function(i) {
      if (docCodes.indexOf(data_attr[i]) == -1) {
        docCodes.push(data_attr[i]) //push that in array
      }
    })
  } else {

    $(data_attr).each(function(i) {
      docCodes.splice(docCodes.indexOf(data_attr[i]), 1)
    })

  }
  console.log(docCodes.toString())


}

$('#selectAll').on('click', function(e) {
  checkAllBox(this, 'activity_selection');
})

function checkAllBox(obj, clsName) {

  if (obj.checked) { // check select status
    $('.' + clsName).each(function() {
      this.checked = true;
      var data_attr = $(this).attr("data-code").split(",")
      $(data_attr).each(function(i) {
        if (docCodes.indexOf(data_attr[i]) == -1) {
          docCodes.push(data_attr[i]) //push that in array
        }
      })


    });
  } else {
    $('.' + clsName).each(function() {
      this.checked = false;
      var data_attr = $(this).attr("data-code").split(",")
      $(data_attr).each(function(i) {
        docCodes.splice(docCodes.indexOf(data_attr[i]), 1)
      })
    });
  }
  console.log(docCodes.toString())
}
#attchment_div {
  display: none;
  border: 1px solid black
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>


<table id="uploadGrid" class="display" width="100%">
  <thead>
    <tr>
      <th class="Greyheader"><input id="selectAll" type="checkbox" /> <br />S.No</th>
      <th class="Greyheader">Document Name</th>
      <th class="Greyheader">Browse</th>
      <th class="Greyheader">Attachment</th>
      <th class="Greyheader">Save</th>
    </tr>
  </thead>
  <tbody>
    <tr id="517">
      <td class="GreyBorder">1&nbsp;&nbsp;<input id="chk_517" class="activity_selection" onclick="addAttr(this);" type="checkbox" data-code="78424,78427,78428" /></td>
      <td class="GreyBorder">CRL</td>
      <td class="GreyBorder" style="text-align: center !important;"><input id="txt_filePath_517" class="mediumTextField" style="width: 78%;" multiple="multiple" name="txt_filePath_517" type="file" /></td>
      <td class="GreyBorder" style="text-align: center !important;" align="center"><span style="cursor: hand;"><span class="attch_counter">3</span><img class="AttachmentBox" title="Attachment" onclick="AttchmentBox('_41701','2',this);" src="../../Images/attchments.png" height="20px" /></span>
      </td>
      <td class="GreyBorder" align="center"><img id="Btn_517" class="AddItem" style="cursor: pointer; height: 15px;" title="Save" src="../../Images/save.png" /></td>
    </tr>
    <tr id="518">
      <td class="GreyBorder">2&nbsp;&nbsp;<input id="chk_518" class="activity_selection" onclick="addAttr(this);" type="checkbox" data-code="78426" /></td>
      <td class="GreyBorder">XYZ</td>
      <td class="GreyBorder" style="text-align: center !important;"><input id="txt_filePath_518" class="mediumTextField" style="width: 78%;" multiple="multiple" name="txt_filePath_518" type="file" /></td>
      <td class="GreyBorder" style="text-align: center !important;" align="center"><span style="cursor: hand;"><span class="attch_counter">1</span><img class="AttachmentBox" title="Attachment" src="../../Images/attchments.png" height="20px" /></span>
      </td>
      <td class="GreyBorder" align="center"><img id="Btn_518" class="AddItem" style="cursor: pointer; height: 15px;" title="Save" src="../../Images/save.png" /></td>
    </tr>
    <tr id="519">
      <td class="GreyBorder">3&nbsp;&nbsp;<input id="chk_519" class="activity_selection" onclick="addAttr(this);" type="checkbox" data-code="78429" /></td>
      <td class="GreyBorder">ABC</td>
      <td class="GreyBorder" style="text-align: center !important;"><input id="txt_filePath_519" class="mediumTextField" style="width: 78%;" multiple="multiple" name="txt_filePath_519" type="file" /></td>
      <td class="GreyBorder" style="text-align: center !important;" align="center"><span style="cursor: hand;"><span class="attch_counter">1</span><img class="AttachmentBox" title="Attachment" src="../../Images/attchments.png" height="20px" /></span>
      </td>
      <td class="GreyBorder" align="center"><img id="Btn_519" class="AddItem" style="cursor: pointer; height: 15px;" title="Save" src="../../Images/save.png" /></td>
    </tr>

  </tbody>
</table>


<div id="attchment_div">
  <table id="AttachmentGrid" style="width: 100%;">
    <tbody>
      <tr>
        <td style="text-align: left; width: 40%;"><input id="chkAttachment_78428" class="attachment_selection" type="checkbox" onclick="addAttributes('78428','41701',this);" />
          <div class="ui-notify-message ui-notify-message-style">
            <div class="image_path" style="float: left; margin: 0 10px 0 0;"><img src="../../Images/attchments.png" /></div>
            <p>Book1.xlsx</p>
          </div>
        </td>
        <td style="text-align: center; width: 35%;">
          <div style="float: left; position: relative; top: -6px;">
            <div class="date"><span class="day">11</span> <span class="month">Jun</span> <span class="year">2021</span></div>
          </div>
        </td>
        <td style="width: 20%; cursor: hand;"><img class="AddItem" style="float: right; padding-bottom: 20px;" title="Delete Attachment" src="../../images/delete.png" /></td>
      </tr>
      <tr>
        <td style="text-align: left; width: 40%;"><input id="chkAttachment_78427" class="attachment_selection" type="checkbox" onclick="addAttributes('78428','41701',this);" />
          <div class="ui-notify-message ui-notify-message-style">
            <div class="image_path" style="float: left; margin: 0 10px 0 0;"><img src="../../Images/attchments.png" /></div>
            <p>ABC.docx</p>
          </div>
        </td>
        <td style="text-align: center; width: 35%;">
          <div style="float: left; position: relative; top: -6px;">
            <div class="date"><span class="day">10</span> <span class="month">Jun</span> <span class="year">2021</span></div>
          </div>
        </td>
        <td style="width: 20%; cursor: hand;"><img class="AddItem" style="float: right; padding-bottom: 20px;" title="Delete Attachment" src="../../images/delete.png" /></td>
      </tr>
      <tr>
        <td style="text-align: left; width: 40%;"><input id="chkAttachment_78424" class="attachment_selection" type="checkbox" onclick="addAttributes('78424','41701',this);" />
          <div class="ui-notify-message ui-notify-message-style">
            <div class="image_path" style="float: left; margin: 0 10px 0 0;"><img src="../../Images/attchments.png" /></div>
            <p>FOSUNDERSTANDING.docx</p>
          </div>
        </td>
        <td style="text-align: center; width: 35%;">
          <div style="float: left; position: relative; top: -6px;">
            <div class="date"><span class="day">09</span> <span class="month">Jun</span> <span class="year">2021</span></div>
          </div>
        </td>
        <td style="width: 20%; cursor: hand;"><img class="AddItem" style="float: right; padding-bottom: 20px;" title="Delete Attachment" src="../../images/delete.png" /></td>
      </tr>
    </tbody>
  </table>
</div>



Vue.js multiple checkbox filter with searchbar filtering and table sorting

I have a vue.js table of pokemons in which I can already search by pokemon's name and generation. And also I can sort the table columns asc/desc if I click in any of them.

I want to introduce multiple checkboxes to this program where I can filter out the table by pokemon types. This checkbox filter should work together with the search filtering, so if I search pokemon generation "IV" with the search field I want to further filter those hits with the checkboxes.

I figured I could not use computed instead I always transfigure my array (pokemonList) to my needs and keep a copy of the original array in a different data variable (originalData). But I don't know how should I implement in this setting the checkbox filtering (checkboxChange method).

This is my template:

<f7-searchbar
    placeholder="Name and generation search"
    :clear-button="true"
    :disable-button="true"
    disable-button-text=""
    v-model:value="searchTerm"
></f7-searchbar>
<div class="filters">
    <f7-checkbox @change="checkboxChange" value="fire"><span>Fire types</span></f7-checkbox>
    <f7-checkbox @change="checkboxChange" value="water"><span>Water types</span></f7-checkbox>
    <f7-checkbox @change="checkboxChange" value="ground"><span>Ground types</span></f7-checkbox>
    <f7-checkbox @change="checkboxChange" value="poison"><span>Poison types</span></f7-checkbox>
</div>


<div class="pokemon-table">
    <table>
    <thead>
        <tr>
        <th @click="sort('name')"><span :class="getSortingDirection('name')"></span>Name</th>
        <th @click="sort('generation')"><span :class="getSortingDirection('generation')"></span>Generation</th>
        <th @click="sort('power')"><span :class="getSortingDirection('power')"></span>Power</th>
        </tr>
    </thead>
    <tbody>
        <tr v-for="pokemon in pokemons" :key="pokemon.id" @click="selectRow(pokemon.id)" :class="{'highlight': (pokemon.id == selectedRow)}">
        <td></td>
        <td></td>
        <td></td>
        </tr>
    </tbody>
    </table>
</div>

And this is my script tag in which

export default {
  data() {
    return {
      originalData: [],
      pokemonList: [],
      searchTerm: '',
      sortBy: '',
      sortOrder: 1,
      selectedRow: null,
    }
  },

  beforeMount() {
    const self = this;
    ajax.methodCall('/Pokemon/Pokemonlist')
    .then(result => self.pokemonList = result.pokemonList)
    .finally(() => self.originalData = self.pokemonList);
  },


  methods: {
    getFilteredList() {
      const self = this;
      let searchData = self.originalData;
      if (self.searchTerm == '') {
        self.pokemonList= self.originalData;
      } else {
        self.pokemonList = searchData.filter(pokemon => {
          const name = pokemon.name.toLowerCase();
          const generation = pokemon.generation.toLowerCase();
          const searchTerm = self.searchTerm.toLowerCase();

          return name.includes(searchTerm) || generation.includes(searchTerm)
        })
      }
    },

    sort(sortBy) {
      const self = this;
      if (self.sortBy == sortBy) {
        self.sortOrder = -self.sortOrder;
      } else {
        self.sortBy = sortBy;
      }

      self.pokemonList= self.pokemonList
        .sort((a,b) => {
          if (a[self.sortBy] >= b[self.sortBy]) {
            return self.sortOrder
          }
        return -self.sortOrder
      })

    },

    getSortingDirection(sortBy) {
      if(sortBy == this.sortBy) {
        return this.sortOrder == 1 ? 'asc' : 'desc';
      }
    },

    selectRow(id) {
      this.selectedRow != id ? this.selectedRow = id : this.selectedRow = null;
    },

    checkboxChange(e) {}
  },

  watch: {
    searchTerm() {
        this.getFilteredList();
    }
  }
}

The data structure of an pokemon in pokemonList is like this:

pokemonList: [
  {
    id: 0,
    name: 'Charizard',
    generation: 'I',
    power: 244,
    type: 'fire',
  },
]