2

我有一个外部下拉表单,其中包含正确和不正确的值,只要选择不正确,ajax 帖子就会运行,并会在 td 内为不正确的值生成一个跨度。我需要的是数据表应该通过检查 td 中的 span 来过滤掉不正确的数据。

HTML:

<select id="filter">
 <option value="correct">Correct</option>
 <option value="incorrect">Incorrect</option>
</select>

//Data Tables
<table id="data">
   <thead>
      <tr>Word</tr>
   </thead>
   <tbody>
      <tr><td>Cat</td></tr>
      <tr><td>Dog</td></tr>
      <tr><td><span="wrong-spelling">Dogr<td></tr>
   </tbody>
</table>

JS:

$(document).ready(function(){
   var dtTable = $('#data').dataTable( {
    "sDom": '<"H"lr>t<"F"ip>',
    "bSort": false,
    "bAutoWidth": false,
    "iDisplayStart": 0,
    "iDisplayLength": 25,
    "bProcessing": true,
    "sPaginationType": "full_numbers",
    "bJQueryUI": true,
            "aoColumns": [
                     {"sType": "string"},
         {"sType": "string"},
                     {"sType": "string"}
        ]       
});      


  $("#filter").change(function(){
     //Ajax Post request to check spelling and will insert span on misspelled words
     dtTable.fnFilter('span');
  });
});

On #filter change, when incorrect is chosen it should only filter rows with span class wrong-spelling

4

0 回答 0