Open felixwann opened 3 years ago
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>Data Tables</title> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.css"> <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script> </head> <body> <table id="example"></table> <script type="text/javascript"> var data = [ { "name": "Tiger Nixon", "position": "System Architect", "salary": "$3,120", "start_date": "2011/04/25", "office": "Edinburgh", "extn": "5421" }, { "name": "Garrett Winters", "position": "Director", "salary": "$5,300", "start_date": "2011/07/25", "office": "Edinburgh", "extn": "8422" } ]; //object可以如下初始化表格 $('#example').DataTable({ data: data, //使用对象数组,一定要配置columns,告诉 DataTables 每列对应的属性 //data 这里是固定不变的,name,position,salary,office 为你数据里对应的属性 columns: [ { data: 'name' }, { data: 'position' }, { data: 'salary' }, { data: 'office' } ] } ); </script> </body> </html>
http://datatables.club/example/ajax/objects.html 自己看例子