Passing UserID into Datatables
在这里工作一个项目,我需要一些帮助。我有一个php页面和一个html页面,试图将php的用户名传递到我的html文件中的DataTable中。我每个人的代码是:
PHP在下面:
1 2 | public function __construct(Guard $auth)if (Auth::check() ||Auth::attempt()) { $auth_id = Auth::user()->id;} |
我的HTML部分如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | var table = $('#example').DataTable( { // Makes one continuous line "autoWidth": false, // How many rows to return "pageLength": 25, // Setup the search box with the current username to filter the values on the screen - jsg 2/12/2016 "search": { "search": $('auth') }, dom:"Bfrtip", ajax:"../php/staff.php", columns: [ { data: null, defaultContent: '', className: 'select-checkbox', orderable: false }, { data:"instructor", visible: false }, { data:"first_name" }, { data:"last_name" }, { data:"category" }, { data:"Metric_text" }, { data:"response_value" }, { data:"fkey_course_id", visible: false }, { data:"course_code" }, { data:"course_number" }, { data:"course_section"} ], |
我的问题是如何使$ auth_id进入HTML编码的搜索部分。如您所见,我已经使用$('auth')尝试了此操作,但是它给了我一个对象错误。如果我尝试使用类似"搜索"的名称:"测试",则测试将填充并且可以正常工作。基本上,我想将用户名传递到DataTable的搜索框中,以使其仅显示用户名行。
您可以使用Ajax。
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $(document).ready(function() { $('#example').DataTable( { "processing": true, "serverSide": true, "ajax":"scripts/ids-objects.php", "columns": [ {"data":"first_name" }, {"data":"last_name" }, {"data":"position" }, {"data":"office" }, {"data":"start_date" }, {"data":"salary" } ] } ); } ); |
看这个例子。
希望它可以为您提供帮助。