Advertisement
Guest User

Untitled

a guest
Oct 28th, 2012
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. $.fn.dataTableExt.afnFiltering.push(
  2. function( oSettings, aData, iDataIndex ) {
  3.  
  4. console.log(aData[1]);
  5. var ret = true;
  6.  
  7. //Loop through all input fields i tfoot that has class 'sl_filter' attached
  8. $('tfoot .sl_filter').each(function(i, obj){
  9.  
  10. //$(this) can be used. Get the index of this colum.
  11. var i2 = $("tfoot input").index($(this));
  12. i2 = oTable.fnVisibleToColumnIndex(i2);
  13.  
  14. //Create regexp to math
  15. var r = new RegExp($(this).val(), "i");
  16.  
  17. //HTML does not get updated when changing value in select, hence searching for :selected return old value
  18. //DataTables stores the DOM object oSettings. Hence, get the object and extract the text for the selected value.
  19. var tr = oSettings.aoData[ iDataIndex ].nTr;
  20. var id = $(aData[i2]).attr('id');
  21.  
  22. //Get the text
  23. var str = "";
  24. var value = "";
  25. if($(aData[i2]).is("form")){
  26. value = $("#" + id + " select", tr).val();
  27. str = $("#" + id + " select option[value='" + value + "']", tr).text();
  28. }else{
  29. value = $("#" + id, tr).val();
  30. str = $("#" + id + " option[value='" + value + "']", tr).text();
  31. }
  32.  
  33. /*Test to see if there is a match or if the input value is the default
  34. (the initial value of input before it has any fokus/text) */
  35. if(r.test(str) || $(this).val()=="Search"){
  36. //Return true only exits this function
  37. return true;
  38. }else{
  39.  
  40. /*Return false returns both function an .each. Retain 'false' in a variable scoped
  41. to be reached outside the .each */
  42. ret = false;
  43. return false;
  44. }
  45. });
  46. //Return true or false
  47. return ret;
  48.  
  49. }
  50. );
  51.  
  52. $.fn.dataTableExt.afnSortData['dom-select'] = function ( oSettings, iColumn, iColumnVis){
  53.  
  54. iColumn = oSettings.oApi._fnColumnIndexToVisible( oSettings, iColumn );
  55. var aData = [];
  56. $( 'td:eq('+iColumn+') select', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
  57. aData.push( $.trim($(":selected", this).text()));
  58. } );
  59.  
  60. return aData;
  61. };
  62.  
  63. str = $('td:eq(' + i2 + ') option:selected', oSettings.aoData[ iDataIndex ].nTr).text();
  64.  
  65. $.fn.dataTableExt.afnFiltering.push(
  66. function( oSettings, aData, iDataIndex ) {
  67.  
  68. var ret = true;
  69.  
  70. //Loop through all input fields i tfoot that has class 'sl_filter' attached
  71. $('tfoot .sl_filter').each(function(i, obj){
  72.  
  73. //$(this) can be used. Get the index of this colum.
  74. var i2 = $("tfoot input").index($(this));
  75.  
  76. //Create regexp to math
  77. var r = new RegExp($(this).val(), "i");
  78.  
  79. //Get the text
  80. var str = $('td:eq(' + i2 + ') option:selected', oSettings.aoData[ iDataIndex ].nTr).text();
  81.  
  82. /*Test to see if there is a match or if the input value is the default
  83. (the initial value of input before it has any fokus/text) */
  84. if(r.test(str) || $(this).val()=="Search"){
  85. //Return true only exits this function
  86. return true;
  87. }else{
  88.  
  89. /*Return false returns both function an .each. Retain 'false' in a variable scoped
  90. to be reached outside the .each */
  91. ret = false;
  92. return false;
  93. }
  94. });
  95. //Return true or false
  96. return ret;
  97. }
  98. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement