Add customizable columns (Edit / Delete)

Add customizable columns (Edit / Delete)

nicoferrero11nicoferrero11 Posts: 1Questions: 1Answers: 0

Hi everyone!!!

I had the next js:
$('#dataTable').DataTable();

and the next html for the table:

<thead>
<tr role="row" id="tableHead" style="color: white;">
<th>Cod. Doc</th>
<th>Descrip</th>
@if (show)
{<th></th>}
</tr>
</thead>
<tbody>
@foreach (var item in Model.Document)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.cod_doc)</td>
<td>@Html.DisplayFor(modelItem => item.descrip)</td>
@if (show)
{
<td>
@if (!item.Delete)
{
<a href="@Url.Action("Edit", "CondIva", new { id = item.Id })" class="edit-icon">
<i class="fa fa-edit"></i>
</a>
<a onclick="return eliminarRegistro(@item.Id, 'CondIva')" class="delete-icon">
<i class="fa fa-close"></i>
</a>
}
</td>
}
</tr>
}
</tbody>

It worked correctly but I need to process many data now, wherewith this solution doesn't work.

So, I realized this:
JS
_ $('#dataTable').DataTable({
"ajax": {
"url": "/Document/GetList",
"type": "POST",
"datatype": "json"
},
"columns": [
{ "data": "cod_doc", "name": "cod_doc" },
{ "data": "descrip", "name": "descrip" },
],
"serverSide": "true",
"order": [0, "asc"],
"processing": "true",
"language": {
"processing": "Processing..."
}
});_

My problem is with the Edit/Delete column, how do I add it? I want to keep the html because it has conditionals.

Thanks!

Answers

  • tonyddtonydd Posts: 2Questions: 1Answers: 0
    edited April 2018

    I have a similar question. If loading data through a JSON variable, is it possible to add custom html/js into the table cells?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    In the case of the original question, you'd need to add the conditions into the Javascript as well. If the Javascript is inline on your page, that shouldn't be a problem, but if you are loading a static file, you'll need to query the DOM to see if the extra columns should be added or not.

    Allan

This discussion has been closed.