Function

コメント・参照等
  • マルチフィルター付きdatatables向けJavascriptコード出力関数

FUN = f_write_datatables_multifilter_jscode.r
function (dt_table = "table.compact", dt_order = "0,\"asc\"", dt_length = c("20,5,1,10,-1", "20,5,1,10,\"All\""), fixed = "leftColumns: 0") 
{
    cat(paste0("<script>$(document).ready(function(){\n  $('", dt_table, " thead th').each( function () {\n    var title = $(this).text();\n    $(this).html( '<input type=\"text\" placeholder=\"'+title+'\" />' );\n  } );\n\n  $('", dt_table, "').DataTable({\n    \"dom\"            : '<\"top\"p>rt<\"bottom\"il><\"clear\">',\n    \"order\"          : [[", dt_order, "]],\n    \"lengthMenu\"     : [[", dt_length[1], "],[", dt_length[2], "]],\n    \"searching\"      : true,\n    \"paging\"         : true,\n    \"ordering\"       : true,\n    \"info\"           : true,\n    \"scrollX\"        : true,\n    \"retrieve\"       : true,\n    \"searchHighlight\": true,\n    \"fixedColumns\"   : {", 
        fixed, "},\n    \"search\"         : {\"regex\": true}", "\n  });\n\n  var table = $('", dt_table, "').DataTable();\n\n  table.columns().every( function () {\n    var that = this;\n    $( 'input', this.header() ).on( 'keyup change', function () {\n      if ( that.search() !== this.value ) {\n        that\n        .search( this.value )\n        .draw();\n      }\n    } );\n  } );\n});</script>"))
}