I am trying to add some texts and string links to a datatable based on the row index.
this is my current part of initialization
<script> var datatablecompanyuser = null; $(document).ready(function () { $.extend(true, $.fn.dataTable.defaults, { "searching": false, "ordering": false, "paging": false }); var dataSourceUrl = "@Url.Action("CompanyUsersList", "Settings")"; datatablecompanyuser = $('#datatablecompanyuser').dataTable({ info: false, ajax: { "url": dataSourceUrl, "type": "GET", }, columns: [ { "data": "Id", "render": function (data, type, row) { return "<label><input type='checkbox' value='" + data + "' name='chkGrid'><span class='text'></span></label>"; } }, { "data": "Fullname" }, { "data": "Email" }, { "data": "CitizenIdNo" }, { "data": "CreateDate", "render": function (data, type, row) { return moment(parseInt(data.substr(6))).format('DD.MM.YYYY hh:mm'); } }, { "data": "Id", "render": function (data, type, row) { var table = $('#datatablecompanyuser').DataTable(); if (table.row().index() == 0){ return "<label>A</label>"} else { return "<label>B</label>"; } } }, { "data": "Id" }, ], language: { "url": "//cdn.datatables.net/plug-ins/1.10.10/i18n/Turkish.json" } }); }); </script>
I am trying to add the text βAβ in the first line and βBβ in other lines.
As you can see from the code above, I tried to do something similar in the corresponding column.
{ "data": "Id", "render": function (data, type, row) { var table = $('#datatablecompanyuser').DataTable(); if (table.row().index() == 0){ return "<label>A</label>";} else { return "<label>B</label>"; } } },
But each line gets A. I am doing something wrong, but I canβt understand that.
I will need the same row index that the next column defines to include the link (or not), but I think if I can solve it, the rest will be easy.