{"id":175199,"date":"2024-11-08T03:52:18","date_gmt":"2024-11-07T19:52:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/175199\/"},"modified":"2024-11-08T03:52:19","modified_gmt":"2024-11-07T19:52:19","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8datatable%e8%bc%95%e9%ac%86%e6%93%8d%e4%bd%9c%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-datatable-%e6%93%8d%e4%bd%9c%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/175199\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Datatable\u8f15\u9b06\u64cd\u4f5c\u6578\u64da\u5eab\uff1f (datatable \u64cd\u4f5c\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8datatable%e8%bc%95%e9%ac%86%e6%93%8d%e4%bd%9c%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-QNRPQngQpK\">\u5982\u4f55\u4f7f\u7528Datatable\u8f15\u9b06\u64cd\u4f5c\u6578\u64da\u5eab\uff1f<\/h1>\n<p>\u5728\u73fe\u4eca\u7684\u7db2\u9801\u958b\u767c\u4e2d\uff0c\u6578\u64da\u7684\u5c55\u793a\u548c\u64cd\u4f5c\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u74b0\u3002Datatable\u662f\u4e00\u500b\u5f37\u5927\u7684jQuery\u63d2\u4ef6\uff0c\u80fd\u5920\u8f15\u9b06\u5730\u5c07HTML\u8868\u683c\u8f49\u63db\u70ba\u529f\u80fd\u8c50\u5bcc\u7684\u6578\u64da\u8868\u683c\uff0c\u4e26\u4e14\u53ef\u4ee5\u8207\u5f8c\u7aef\u6578\u64da\u5eab\u9032\u884c\u4ea4\u4e92\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Datatable\u4f86\u64cd\u4f5c\u6578\u64da\u5eab\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u66f4\u9ad8\u6548\u5730\u7ba1\u7406\u6578\u64da\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afdatatable%ef%bc%9f-QNRPQngQpK\">\u4ec0\u9ebc\u662fDatatable\uff1f<\/h2>\n<p>Datatable\u662f\u4e00\u500b\u57fa\u65bcjQuery\u7684\u63d2\u4ef6\uff0c\u63d0\u4f9b\u4e86\u8a31\u591a\u529f\u80fd\uff0c\u5982\u6392\u5e8f\u3001\u641c\u5c0b\u3001\u5206\u9801\u7b49\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u8f15\u9b06\u5730\u8655\u7406\u5927\u91cf\u6578\u64da\u3002\u5b83\u7684\u4f7f\u7528\u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u5e7e\u884c\u4ee3\u78bc\u5373\u53ef\u5c07\u666e\u901a\u7684HTML\u8868\u683c\u8f49\u63db\u70ba\u52d5\u614b\u7684\u6578\u64da\u8868\u683c\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9ddatatable-QNRPQngQpK\">\u5b89\u88ddDatatable<\/h2>\n<p>\u8981\u4f7f\u7528Datatable\uff0c\u9996\u5148\u9700\u8981\u5728\u4f60\u7684\u9805\u76ee\u4e2d\u5f15\u5165jQuery\u548cDatatable\u7684CSS\u53caJS\u6587\u4ef6\u3002\u53ef\u4ee5\u901a\u904eCDN\u4f86\u5feb\u901f\u5f15\u5165\uff1a<\/p>\n<pre><code>&lt;link rel=\"stylesheet\" href=\"https:\/\/cdn.datatables.net\/1.10.21\/css\/jquery.dataTables.min.css\"&gt;\n&lt;script src=\"https:\/\/code.jquery.com\/jquery-3.5.1.js\"&gt;&lt;\/script&gt;\n&lt;script src=\"https:\/\/cdn.datatables.net\/1.10.21\/js\/jquery.dataTables.min.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n<h2 id=\"%e5%89%b5%e5%bb%bahtml%e8%a1%a8%e6%a0%bc-QNRPQngQpK\">\u5275\u5efaHTML\u8868\u683c<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5275\u5efa\u4e00\u500bHTML\u8868\u683c\uff0c\u9019\u500b\u8868\u683c\u5c07\u7528\u4f86\u986f\u793a\u5f9e\u6578\u64da\u5eab\u4e2d\u7372\u53d6\u7684\u6578\u64da\uff1a<\/p>\n<pre><code>&lt;table id=\"example\" class=\"display\" style=\"width:100%\"&gt;\n    &lt;thead&gt;\n        &lt;tr&gt;\n            &lt;th&gt;\u59d3\u540d&lt;\/th&gt;\n            &lt;th&gt;\u5e74\u9f61&lt;\/th&gt;\n            &lt;th&gt;\u8077\u696d&lt;\/th&gt;\n        &lt;\/tr&gt;\n    &lt;\/thead&gt;\n    &lt;tbody&gt;\n        &lt;!-- \u6578\u64da\u5c07\u5728\u9019\u88e1\u52d5\u614b\u52a0\u8f09 --&gt;\n    &lt;\/tbody&gt;\n&lt;\/table&gt;<\/code><\/pre>\n<h2 id=\"%e5%be%9e%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8d%b2%e5%8f%96%e6%95%b8%e6%93%9a-QNRPQngQpK\">\u5f9e\u6578\u64da\u5eab\u7372\u53d6\u6578\u64da<\/h2>\n<p>\u70ba\u4e86\u5f9e\u6578\u64da\u5eab\u7372\u53d6\u6578\u64da\uff0c\u6211\u5011\u9700\u8981\u4f7f\u7528\u5f8c\u7aef\u8a9e\u8a00\uff08\u5982PHP\uff09\u4f86\u67e5\u8a62\u6578\u64da\u5eab\u4e26\u8fd4\u56deJSON\u683c\u5f0f\u7684\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684PHP\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"database\";\n\n\/\/ \u5275\u5efa\u9023\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\n\/\/ \u6aa2\u67e5\u9023\u63a5\nif ($conn-&gt;connect_error) {\n    die(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n\n$sql = \"SELECT name, age, occupation FROM users\";\n$result = $conn-&gt;query($sql);\n\n$data = array();\nif ($result-&gt;num_rows &gt; 0) {\n    while($row = $result-&gt;fetch_assoc()) {\n        $data[] = $row;\n    }\n}\necho json_encode($data);\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<h2 id=\"%e5%88%9d%e5%a7%8b%e5%8c%96datatable-QNRPQngQpK\">\u521d\u59cb\u5316Datatable<\/h2>\n<p>\u5728\u7372\u53d6\u5230\u6578\u64da\u5f8c\uff0c\u6211\u5011\u9700\u8981\u5728JavaScript\u4e2d\u521d\u59cb\u5316Datatable\u4e26\u52a0\u8f09\u6578\u64da\uff1a<\/p>\n<pre><code>$(document).ready(function() {\n    $('#example').DataTable({\n        \"ajax\": \"path\/to\/your\/php\/file.php\",\n        \"columns\": [\n            { \"data\": \"name\" },\n            { \"data\": \"age\" },\n            { \"data\": \"occupation\" }\n        ]\n    });\n});<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-QNRPQngQpK\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528Datatable\u4f86\u64cd\u4f5c\u6578\u64da\u5eab\u4e0d\u50c5\u80fd\u5920\u63d0\u9ad8\u958b\u767c\u6548\u7387\uff0c\u9084\u80fd\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6236\u9ad4\u9a57\u3002\u901a\u904e\u7c21\u55ae\u7684\u8a2d\u7f6e\u548c\u4ee3\u78bc\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5c07\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u5c55\u793a\u5728\u7db2\u9801\u4e0a\uff0c\u4e26\u63d0\u4f9b\u5f37\u5927\u7684\u4ea4\u4e92\u529f\u80fd\u3002\u5c0d\u65bc\u9700\u8981\u8655\u7406\u5927\u91cf\u6578\u64da\u7684\u61c9\u7528\u4f86\u8aaa\uff0cDatatable\u7121\u7591\u662f\u4e00\u500b\u7406\u60f3\u7684\u9078\u64c7\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u7db2\u7ad9\u6216\u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u6700\u4f73\u7684\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528Datatable\u8f15\u9b06\u64cd\u4f5c\u6578\u64da\u5eab\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u6548\u7387\uff0c\u7c21\u5316\u67e5\u8a62\u548c\u986f\u793a\u904e\u7a0b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-175199","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=175199"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175199\/revisions"}],"predecessor-version":[{"id":175200,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175199\/revisions\/175200"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=175199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=175199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=175199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}