Hello Team, Please how do I prevent the edit and delete column from showing on the excel sheet.

Hello Team, Please how do I prevent the edit and delete column from showing on the excel sheet.

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Jan 6, 2024, 12:37 PM EST
You can use the exportOptions property for each column. In your case, for the "Edit" and "Delete" columns, you can set the exportOptions property to { visible: false }.
$(document).ready(function () { dataTable = $("#ItemInfo").DataTable({ "processing": false, "serverSide": false, "paging": true, "destroy": true, "order": [[0, 'desc']], "pageLength": 25, buttons: [ { extend: 'excel', className: 'btn btn-dark rounded-0 ', text: ' Excel', title: 'Smart App', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] // Exclude "Edit" and "Delete" columns from export } }, ], dom: 'lTfgitp', "columns": [ { "data": "PCode" }, { "data": "OrderDate" }, { "data": "CategoryName" }, { "data": "ProductName" }, { "data": "UnitPrice" }, { "data": "Quantity" }, { "data": "TotalAmount" }, { "data": null, "width": "50px", "render": function (data, type, full, meta) { return "Edit"; }, "exportOptions": { visible: false // Exclude "Edit" column from export } }, { "data": "StockInHistoryId", "width": "50px", "render": function (data) { return "Delete"; }, "exportOptions": { visible: false // Exclude "Delete" column from export } }, ], "ajax": { "url": "/Home/GetAllStockInHistory", "type": "GET", "dataSrc": "[]", } }); });In the exportOptions property for the Excel button, I specified the columns to be exported (0 to 6) and set the visible: false property for the "Edit" and "Delete" columns to exclude them from the export.
Emmmanuel FIADUFERank #947 · 2.2K reputationPosted Jan 6, 2024, 6:12 AM EST
I export data from my DataTable into excel, it include the edit and delete column
$(document).ready(function () {
dataTable = $("#ItemInfo").DataTable({
"processing": false,
"serverSide": false,
"paging": true,
"destroy": true,
"order":[[0,'desc']],
pageLength: 25,
buttons: [
{ extend: 'excel', className: 'btn btn-dark rounded-0 ', text: ' Excel', title: 'Smart App' },
],
dom: '<"html5buttons"B>lTfgitp',
"columns": [
{ "data": "PCode" },
{ "data": "OrderDate" },
{ "data": "CategoryName" },
{ "data": "ProductName" },
{ "data": "UnitPrice" },
{ "data": "Quantity" },
{ "data": "TotalAmount" },
{
"data": null, "width": "50px", "render": function (data, type, full, meta) { return "Edit"; }
},
{
"data": "StockInHistoryId", "width": "50px", "render": function (data) { return "Delete"; }
},
],
"ajax": {
"url": "/Home/GetAllStockInHistory",
"type": "GET",
"dataSrc": "[]",
}
});
});
Sachin SinghRank #66 · 26.2K reputationPosted Jan 6, 2024, 12:50 PM EST
use this it works fine
$(document).ready(function () { dataTable = $("#ItemInfo").DataTable({ "processing": false, "serverSide": false, "paging": true, "destroy": true, "order": [[0, 'desc']], pageLength: 25, buttons: [ { extend: 'excel', className: 'btn btn-dark rounded-0', text: ' Excel', title: 'Smart App', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] // Specify the columns to include in the export } } ], dom: 'lTfgitp', "columns": [ { "data": "PCode" }, { "data": "OrderDate" }, { "data": "CategoryName" }, { "data": "ProductName" }, { "data": "UnitPrice" }, { "data": "Quantity" }, { "data": "TotalAmount" }, ], "ajax": { "url": "/Home/GetAllStockInHistory", "type": "GET", "dataSrc": "[]", } }); });Ali BenchaabanRank #925 · 2.2K reputationPosted Jan 6, 2024, 1:01 PM EST
Hello,
Could you give us more context about your query ?
Are you looking for a solution using Excel sheets ? Or it's used within a C# code ?
Regards,
BENCHAABAN Ali
Emmmanuel FIADUFERank #947 · 2.2K reputationPosted Jan 7, 2024, 12:22 PM EST
Thank you team,
it is working now, my appreciation goes to you all for your continuence support