Answers for "filter column table html"

1

html table filter by all columns

function myFunction() {
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  var rows = table.getElementsByTagName("tr");
  for (i = 0; i < rows.length; i++) {
    var cells = rows[i].getElementsByTagName("td");
    var j;
    var rowContainsFilter = false;
    for (j = 0; j < cells.length; j++) {
      if (cells[j]) {
        if (cells[j].innerHTML.toUpperCase().indexOf(filter) > -1) {
          rowContainsFilter = true;
          continue;
        }
      }
    }

    if (! rowContainsFilter) {
      rows[i].style.display = "none";
    } else {
      rows[i].style.display = "";
    }
  }
}
Posted by: Guest on February-26-2020
0

filter table search

new Vue({
  el: '#demo',

  data: {
    sortKey: 'name',
    reverse: false,
    searchName: '',
    searchOperator: '',
    searchAge: '',
    columns: ['name', 'age'],
    newUser: {},
    search: "",
    name: "",
    age: "",

    users: [
      { name: 'John', age: 50 },
      { name: 'Jane', age: 22 },
      { name: 'Paul', age: 34 },
      { name: 'Kate', age: 15 },
      { name: 'Amanda', age: 65 },
      { name: 'Steve', age: 38 },
      { name: 'Keith', age: 21 },
      { name: 'Don', age: 50 },
      { name: 'Susan', age: 21 }
    ]
  },
  methods: {
    sortBy: function (sortKey) {
      this.reverse = (this.sortKey == sortKey) ? !this.reverse : false;

      this.sortKey = sortKey;
    }, 
    filterByName : function(user) {
      // no search, don't filter : 
      if (this.searchName.length === 0) {
        return true;
      }

      return  (user.name.toLowerCase().indexOf(this.searchName.toLowerCase()) > -1);
    }, 
    filterByAge : function (user) {
      // no operator selected or no age typed, don't filter : 
      if (this.searchOperator.length === 0 || this.age.length === 0) {
        return true;
      }

      if (this.searchOperator === '>') {
        return (user.age > this.age); 
      } else  if (this.searchOperator === '<') {
        return (user.age < this.age);
      }      
    }, 
    orderBy : function (userA, userB) {
      let condition = (userA[this.sortKey] > userB[this.sortKey]);
      if (this.reverse) {
        return !condition;
      } else {
        return condition;
      }
    }
  },
  computed: {
    filteredPersons: function () {
      return this.users
      .filter(this.filterByName)
      .filter(this.filterByAge)
      .sort(this.orderBy);
    }
  },  
});
Posted by: Guest on May-08-2020
0

html table column filter dropdown

<div class="table-wrapper">
    <div class="table-title">
    </div>
        <div class="table-filter">
            <div class="row">
                <div class="col-sm-3">
                    <div class="show-entries">
                        <span>Show</span>
                        <select class="form-control">
                            <option>5</option>
                            <option>10</option>
                        </select>
                        <span>entries</span>
                    </div>
                </div>
                <div class="col-sm-9">
                    <div class="filter-group">
                        <label>Status</label>
                        <select class="form-control">
                            <option>Any</option>
                            <option>Completed</option>
                            <option>In Progress</option>
                            <option>To Run</option>
                        </select>
                    </div>
                <span class="filter-icon"><i class="fa fa-filter"></i></span>
                </div>
            </div>
        </div>
    <form method="post" action="activeInactive.php">
        <table class="paginated table table-striped table-hover">
            <thead>
                <tr>
                    <th>Test Name</th>
                    <th>Created By</th>
                    <th>Last updated</th>
                    <th>Test status</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody id="test_table">

                <?PHP

                $test_access = 0;
                while($row = mysqli_fetch_array($tests_under_user)){    
                    echo '<td width=250px; title="'.$testName.'"><a href="">'.$row['name'].'</a></td>';
                    echo '<td title="'.$row['created'].'">'.$row['created'].'</td>';
                    echo '<td title="'.$row['edited'].'">'.$row['edited'].'</td>';
                    echo '<td>In Progress</td>';
                    echo '<td>';
                    echo '<a href="" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit"></i></a>';   
                    echo '<a href="" class="delete" name="delete" data-toggle="modal" Onclick="return ConfirmDelete()"><i class="material-icons" data-toggle="tooltip" title="Delete"></i></a>';
                    echo '<a href="" class="copy" name="copy" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Copy" style="color: #2874A6">file_copy</i></a>';
                    echo '</td>';
                }
                ?>
            </tbody>
        </table>
    </form>
</div>
Posted by: Guest on August-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language