Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate DataTables filter/sort indicies after fnDrawCallback
    primarykey
    data
    text
    <p>I'm using the <a href="http://timeago.yarp.com/" rel="nofollow">timeago jquery plugin</a> to format timestamps in columns of my <a href="http://datatables.net/" rel="nofollow">data table</a>. The <code>fnDrawCallback</code> DataTables option allows me to set / update formatted timestamps like:</p> <pre><code>&lt;abbr class="timeago" title="2008-07-17T09:24:17Z"&gt;July 17, 2008&lt;/abbr&gt; </code></pre> <p>into a more human readable <code>2 years ago</code>. This gets called anytime there is a table redraw so it works for pagination, server calls, etc. </p> <pre><code>myTable = $('#example').dataTable({ "fnDrawCallback" : function () { $("abbr.timeago").timeago() }, "aaData" : tableData, "aoColumns" : tableHeadings, "oSearch" : {"sSearch" : "", "bRegex" : true, "bSmart" : true, }, }); </code></pre> <p>However, <code>fnDrawCallback</code> does not update the search indicies so querying <code>years</code> returns nothing. Is there a way to force DataTables to update its search indicies?</p> <p><strong>Edit</strong> </p> <p>For clarity I initialize <code>tableData</code> and <code>tableHeadings</code> an array of hashes passed in through JSON. This seems to work fine, as this data shows up in the table without a hitch. The issue is that the Timeago modifies the DOM on the <code>fnDrawCallback</code> which happens after the filter / sort indicies for the table have been populated.</p> <pre><code>// tableHeadings === ['a', 'b', 'DateOne', 'DateTwo', ...] for(i=0; i&lt;tableHeadings.length; i++) { tableHeadings[i] = { "sTitle" : tableHeadings[i], }; if(tableHeadings[i].sTitle.match(/Date/)) { tableHeadings[i].fnRender = function (c) { // closure over i return function (o) { var iso_time = o.aData[c].replace(/\s/, "T") + "Z"; return '&lt;abbr class="timeago" title="'+iso_time+'"&gt;'+'&lt;/abbr&gt;'; } }(i); } } </code></pre> <p>So I can search for the <code>iso_time</code>, but not <code>2 years ago</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload