Is it possible to define specific width for each columns in datatable?
Is it possible to define specific width for each columns in datatable?
jazz0101
Posts: 2Questions: 1Answers: 1
Hi Guys,
First of all I am newbie for this datatable. I am using .Net/c# with MVC 1 and Datatable legacy for my project. I have added datatable but I am having some issues. I am unable to define specific width for each columns. Below is my code, what am I missing here.
var branchId = '<%=ViewData["branchId"]%>';
$.ajax({
url: '/Home.mvc/Home/GetDataDT',
method: 'post',
dataType: 'json',
data: {
branchId: branchId
},
success: function (data) {
data.forEach(function (row) {
row.push('<a id="iconEdit' + row[0] + '" name="EditData" href="<%=this.Url.Action("GetDataByID","Admin") %>?branchId=<%= Convert.ToInt32(this.ViewData["branchId"]) %>&Id=' + row[0] + '" title="Edit Data" class="actionButton" height="300px" width="610px"><span>Edit</span></a>')
});
$('#DataOp').dataTable({
"bPaginate": true,
"sPaginationType": "full_numbers",
"bSearchable": true,
"bAutoWidth": false,
"iDisplayLength": 10,
"bJQueryUI": true,
"aaData": data,
"aoColumns": [
{ mData: 'Id', "bVisible": false, "bSearchable": false },
{ mData: 'Name', "sWidth": "68px fixed" },
{ mData: 'Details', "sWidth": "125px fixed" },
{ mData: 'Functions', "sWidth": "20px fixed" }
]
});
}
});
will sWidth be used in aoColumns. If not how can I mention it.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Found the solution. Added this and it seems to be working.
Example
"aoColumnDefs": [
{ "sWidth": "750px", "aTargets": [2] }
],
columns.width
is the preferred naming scheme (or more specificallycolumnDefs.width
in this case), but either will work.Allan