在数据表pdf导出中添加序列号列

add serial number column in datatable pdf export

我在我的项目中使用 html 和 javascript 从事电子商务项目。作为一部分,我需要显示订购产品的详细信息。我正在使用 Jquery 数据表以便显示详细信息。我需要将详细信息从数据表导出到 excel 并使用。这一切都很好,但问题是我需要在导出时添加序列号我尝试了几种方法。下面是导出按钮

buttons: [
        {
          extend: "excel",
          footer: true,
          title: "my report",
          exportOptions: {
            columns: [1, 2, 3, 4],
          },
        },
        {
          extend: "pdf",
          footer: true,
          title: "my report",
          exportOptions: {
            columns: [1, 2, 3, 4],
          },
        },
      ]

我添加了第零列以及 pdf 导出。但是在过滤后导出 pdf 时失败

请帮我解决这个问题?如果需要任何清晰度请评论我会尽力

您可以在导出为 pdf 或 excel 通过以下代码自定义数据表中的字段。

buttons: [
        {
          extend: "excel",
          footer: true,
          title: "my report",
          exportOptions: {
            columns: [1, 2, 3, 4],
          },
        },
        {
          extend: "pdf",
          footer: true,
          title: "my report",
          exportOptions: {
            columns: [1, 2, 3, 4],
          },
          customize: function (doc) {
            var col = doc.content[1].table.body;
            for (i = 1; i < col.length; i++) {
              col[i][0]["text"] = i;
            }
          },
        },
      ]