Advertisement
Guest User

Untitled

a guest
May 13th, 2011
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript" charset="utf-8">
  2.   /* <![CDATA[ */
  3.   (function($) {
  4.  
  5.     $.fn.dataTableExt.oApi.fnGetColumnData = function(oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty) {
  6.       // check that we have a column id
  7.       if (typeof iColumn == "undefined") return new Array();
  8.  
  9.       // by default we only wany unique data
  10.       if (typeof bUnique == "undefined") bUnique = true;
  11.  
  12.       // by default we do want to only look at filtered data
  13.       if (typeof bFiltered == "undefined") bFiltered = true;
  14.  
  15.       // by default we do not wany to include empty values
  16.       if (typeof bIgnoreEmpty == "undefined") bIgnoreEmpty = true;
  17.  
  18.       // list of rows which we're going to loop through
  19.       var aiRows;
  20.  
  21.       // use only filtered rows
  22.       if (bFiltered == true) aiRows = oSettings.aiDisplay;
  23.       // use all rows
  24.       else aiRows = oSettings.aiDisplayMaster; // all row numbers
  25.       // set up data array 
  26.       var asResultData = new Array();
  27.  
  28.       for (var i = 0, c = aiRows.length; i < c; i++) {
  29.         iRow = aiRows[i];
  30.         var aData = this.fnGetData(iRow);
  31.         var sValue = aData[iColumn];
  32.  
  33.         // ignore empty values?
  34.         if (bIgnoreEmpty == true && sValue.length == 0) continue;
  35.  
  36.         // ignore unique values?
  37.         else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
  38.  
  39.         // else push the value onto the result data array
  40.         else asResultData.push(sValue);
  41.       }
  42.  
  43.       return asResultData;
  44.     }
  45.   }(jQuery));
  46.  
  47.  
  48.   function fnCreateSelect(aData) {
  49.     var r = '<select><option value=""></option>',
  50.         i, iLen = aData.length;
  51.     for (i = 0; i < iLen; i++) {
  52.       r += '<option value="' + aData[i] + '">' + aData[i] + '</option>';
  53.     }
  54.     return r + '</select>';
  55.   }
  56.  
  57.  
  58.   $(document).ready(function() { /* Initialise the DataTable */
  59.     var oTable = $('#wp-table-reloaded-id-1-no-1').dataTable({
  60.       "oLanguage": {
  61.         "sSearch": "Search all columns:"
  62.       }
  63.     });
  64.  
  65.     /* Add a select menu for each TH element in the table footer */
  66.     $("tfoot th").each(function(i) {
  67.  
  68.       this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i));
  69.       $('select', this).change(function() {
  70.         oTable.fnFilter($(this).val(), i);
  71.       });
  72.     });
  73.   }); /* ]]> */
  74. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement