{"id":12225,"date":"2023-05-24T17:54:59","date_gmt":"2023-05-24T09:54:59","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=12225"},"modified":"2023-06-01T14:21:30","modified_gmt":"2023-06-01T06:21:30","slug":"datatable-%e5%a5%97%e7%94%a8-bootstrap-5-tooltip","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=12225","title":{"rendered":"DataTable 1.12 - \u5957\u7528 Bootstrap 5 Tooltip"},"content":{"rendered":"<p>--<\/p>\n<h2>\u53c3\u8003\u8cc7\u6e90<\/h2>\n<ul>\n<li><a href=\"https:\/\/datatables.net\/forums\/discussion\/72985\/bootstrap-tooltip-doesnt-not-work-in-childrow\" target=\"_blank\" rel=\"noopener\">Bootstrap Tooltip doesn't not work in childrow \u2014 DataTables forums<\/a><\/li>\n<li><a href=\"https:\/\/live.datatables.net\/sofubola\/53\/edit\" target=\"_blank\" rel=\"noopener\">DataTables - JS Bin<\/a><\/li>\n<\/ul>\n<p>\u95dc\u9375\u5c31\u662f\u5fc5\u9808\u8981\u628a js \u653e\u5728 initComplete: \u5167<\/p>\n<p>--<\/p>\n<h2>\u61c9\u7528<\/h2>\n<p>HTML<\/p>\n<pre class=\"lang:default decode:true\">&lt;!-- jQuery --&gt;\r\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js\"&gt;&lt;\/script&gt;\r\n\r\n&lt;!-- bootstrap 5 --&gt;\r\n&lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.3\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\r\n&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.3\/dist\/js\/bootstrap.bundle.min.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>JavsScript<\/p>\n<pre class=\"lang:default decode:true\">let data_table = $table.DataTable({\r\n    fixedHeader: true,\r\n    serverSide: true,\r\n    dom: '&lt;\"top\"i&gt;rt&lt;\"bottom\"flp&gt;&lt;\"clear\"&gt;',\r\n    displayLength: 30, \/\/ \u9810\u8a2d\u6bcf\u9801\u7b46\u6578\r\n    lengthChange: false,\r\n    language: {\r\n        url: '\/\/cdn.datatables.net\/plug-ins\/1.12.1\/i18n\/zh-HANT.json'\r\n    },\r\n    searching: false,\r\n    scrollX: true,\r\n    scrollCollapse: true,\r\n    Info: false,\r\n    ordering: false,\r\n    order: [],\r\n    ajax: {\r\n        url: '\/v2\/Stock_item\/select',\r\n        type: 'POST',\r\n        data: function (d) {\r\n            d['search'] = $id_form_search.serialize();\r\n        },\r\n    },\r\n    initComplete: function(settings, json) {\r\n        $('[data-bs-toggle=\"tooltip\"]').tooltip( );\r\n    },\r\n    columns:  [\r\n        {\r\n            data: 'id',\r\n            createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {\r\n                $(cell).attr('data-title', 'id')\r\n            },\r\n        },\r\n        {\r\n            data: 'create_time',\r\n            createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {\r\n                $(cell).attr('data-title', '\u5efa\u7acb\u65e5\u671f')\r\n            },\r\n        },\r\n        {\r\n            data: 'name',\r\n            createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {\r\n                $(cell).attr('data-title', '\u540d\u7a31')\r\n            },\r\n        },\r\n        {\r\n            data: null,\r\n            render: function (data, type, row) {\r\n                let r = '';\r\n                r += '&lt;button type=\"button\" class=\"btn btn-sm btn-outline-primary\" data-bs-toggle=\"tooltip\" data-bs-custom-class=\"primary-tooltip\" data-bs-title=\"\u7de8\u8f2f\" onclick=\"modal_edit(' + data['id'] + ', this)\"&gt;&lt;i class=\"fa-solid fa-pen-to-square\"&gt;&lt;\/i&gt;&lt;\/button&gt; ';\r\n                r += '&lt;button type=\"button\" class=\"btn btn-sm btn-outline-danger\" data-bs-toggle=\"tooltip\" data-bs-custom-class=\"danger-tooltip\" data-bs-title=\"\u522a\u9664\" onclick=\"modal_delete(' + data['id'] + ')\"&gt;&lt;i class=\"fa-solid fa-ban\"&gt;&lt;\/i&gt;&lt;\/button&gt;';\r\n\r\n                return r;\r\n            }\r\n        }\r\n    ],\r\n});<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"12225\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,053&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>-- \u53c3\u8003\u8cc7\u6e90 Bootstr...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"12225\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,053&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[262],"tags":[165,342],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/12225"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12225"}],"version-history":[{"count":4,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/12225\/revisions"}],"predecessor-version":[{"id":12501,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/12225\/revisions\/12501"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}