vendredi 24 juin 2016

Bootstrap Table filter by string partial


I'm using the Bootstrap-table plugin (http://bootstraptable.wenzhixin.net.cn/documentation/) and I'm trying to filter by tags by utilizing the method filterby but can't figure out how to factor in multiple tags that has to come in as a string, separated by commas.

I created an example to illustrate what I'm attempting to achieve. For simplicity,

Here's the html:

<table id="table">
    <thead>
    <tr>
        <th data-field="date">Date</th>
        <th data-field="desc">Description</th>
        <th data-field="tags">Tags</th>
    </tr>
    </thead>
</table>
<br>
<button id="filter-general">General</button>
<button id="filter-rotation">Rotation</button>
<button id="clear">clear</button>

Javascript:

var data = [{
  "date": "2016-05-10",
  "tags": "General, Research, Rotation",
  "desc": "Nunc velit lectus, ornare vitae fringilla eget, vestibulum quis tortor."
},{
  "date": "2016-04-22",
  "tags": "General",
  "desc": "Nunc velit lectus, ornare vitae fringilla eget, vestibulum quis tortor."
},{
  "date": "2016-03-23",
  "tags": "Research, Rotation",
  "desc": "Nunc velit lectus, ornare vitae fringilla eget, vestibulum quis tortor."
},{
  "date": "2015-11-01",
  "tags": "Rotation",
  "desc": "Nunc velit lectus, ornare vitae fringilla eget, vestibulum quis tortor."
},{
  "date": "2016-08-15",
  "tags": "General, Rotation",
  "desc": "Nunc velit lectus, ornare vitae fringilla eget, vestibulum quis tortor."
}];

$(function() {
  $table = $('#table');
  $table.bootstrapTable({
    data: data
  });

  $('#clear').click(function() {
    $table.bootstrapTable('filterBy', {});
  });

  $('#filter-general').click(function() {
    $table.bootstrapTable('filterBy', {
      tags: "General"
    });
  });

  $('#filter-rotation').click(function() {
    $table.bootstrapTable('filterBy', {
      tags: "Rotation"
    });
  });
});

http://jsfiddle.net/zqxwr3uL/6/


Aucun commentaire:

Enregistrer un commentaire