Independent Filters in R

Independent Filters in R

enjoypbenjoypb Posts: 31Questions: 12Answers: 0

I have a table with filters that I place above my table to help users limit records they see by a multitude of options. Things like neighborhood, council district, type of business etc. I'm converting over to using R as a foundation for my datatables (and charts, maps etc.).

I've been unable to replicate the Filters function I have in plain JS over to R. Is there a way I can add this JS function and table output code to an R DataTables table? I'm a relative hack at this but, got this far so there is hope!

A photo of this example is attached.
Default is all boxes unchecked and when one is checked, it limits the data to that criteria (ie. all Applications). Here's what my code looks like:

**#JS FilterMe Function:**

      $(function() {
        licenses = $('#busLicense').dataTable();
      })

          function filterme() {
            //build a regex filter string with an or(|) condition
            //checkboxes
               //class = Business license {class} - col 1
            var Classes = $('input:checkbox[name="class"]:checked').map(function() {
              return '^' + this.value + '\$';
            }).get().join('|');
            //filter in column 15, with an regex, no smart filtering, no inputbox,not case sensitive
            licenses.fnFilter(Classes, 1, true, false, false, false);

                //Active Status - check to limit to {status} = 'ACTIVE' col 3
            var Masters = $('input:checkbox[name="master"]:checked').map(function() {
              return '^' + this.value + '\$';
            }).get().join('|');
            //filter in column 4, with an regex, no smart filtering, no inputbox,not case sensitive
            licenses.fnFilter(Masters, 11, true, false, false, false);

**User selectors choose are:**

  <body style="font-size:10px !important;">
   <div class="container-fluid">

   <!-- FILTER FUNCTIONS - HTML Note these correlate with script. Value shown is what is available from data.
        Name indicates col name. Any text can be displayed to user.  Checked status indicates records included -->
<!-- Status & Class Selectors, select to focus on one or more. For Class: show all by default. -->
<b>All licenses shown by default. Limit licenses by selecting any of the following filters:</b><br /><br />
    <div class="row">
      <div class="col-md-2">
        <b>LICENSES OR APPLICATIONS</b>
      </div>
      <div class="col-md-3">
        <input onchange="filterme()" type="checkbox" name="lic_app" value="LIC"> Licenses&nbsp;&nbsp;&nbsp;&nbsp;
        <input onchange="filterme()" type="checkbox" name="lic_app" value="APP"> Applications
      </div>
    </div>
  <hr class="hr_selectors"/>
    <div class="row">
      <div class="col-md-2">
        <b>MASTER & STATUS</b>
      </div>
      <div class="col-md-4">
        <input onchange="filterme()" type="checkbox" name="master" value="Y" > Master&nbsp;&nbsp;&nbsp;&nbsp;
        <input onchange="filterme()" type="checkbox" name="master" value="N" > Non-Master&nbsp;&nbsp;&nbsp;&nbsp;
        <input onchange="filterme()" type="checkbox" name="status" value="ACTIVE" > Active&nbsp;&nbsp;&nbsp;&nbsp;
        <input onchange="filterme()" type="checkbox" name="status" value="PEND" > Pending
      </div>
    </div>
</div>

**And the actual table appears as:**

   <!-- datatable -->
    <div class="row">
      <div class="col-md-12">
        <table id="busLicense" class="table compact display dt-responsive nowrap" width="100%">
          <thead>
            <tr>
              <th>License-Application</th>
              <th>Master</th>
              <th>Status</th>
              <th>Class</th>
              <th>Outlet Name</th>
              <th>City</th>
            </tr>
          </thead>
          <tfoot>
            <tr>
              <th>License-Application</th>
              <th>Master</th>
              <th>Status</th>
              <th>Class</th>
              <th>Outlet Name</th>
              <th>City</th>
            </tr>
          </tfoot>
        </table>
      </div>
    </div>

Thank you!

Answers

  • enjoypbenjoypb Posts: 31Questions: 12Answers: 0

    If anyone has any insight on this I'd appreciate the help. Thanks!

This discussion has been closed.