There is a table of this type:
<table id="UsersTable" class="table table-responsive table-striped"> <thead> <tr> <th></th> <th>ФИО</th> <th>Компания</th> <th>Должность</th> <th>Телефон</th> </tr> </thead> @foreach (var items in Model) { <tr> <td id ="idrow" class="details-control" data-assigned-id="@items.ADUsersId">@items.ADUsersId</td> <td>@Html.DisplayFor(modelItem => items.DisplayName)</td> <td>@Html.DisplayFor(modelItem => items.Company)</td> <td>@Html.DisplayFor(modelItem => items.Department)</td> <td>@Html.DisplayFor(modelItem => items.TelephoneNumber)</td> </tr> } </table> Everything works fine, sort of like, but in jQuery I'm not really strong. The fact is that when you click a button, the list opens in the column and the button should change accordingly, but this does not happen to me.
When pressed, a button with a minus should appear. Here is my CSS
td.details-control { background: url('img/details_open.png') no-repeat center center; cursor: pointer; } td.shown td.details-control { background: url('img/details_close.png') no-repeat center center; cursor: pointer; } JQuery itself
$(document).ready(function() { var table = $('#UsersTable').DataTable({ "iDisplayLength": 5, "language": { "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Russian.json" }, }); $('#UsersTable').on('click', 'td.details-control', function () { var td = $(this).closest('td'); var row = table.row(td); var id = $('#idrow').attr('data-assigned-id'); $.ajax({ url: '@Url.Action("Details", "Users")', type: 'post', data: { id: id }, dataType: "json", success: function (data) { if (row.child.isShown()) { row.child.hide(); td.removeClass('shown'); } else { // Open this row row.child(format({ 'ФИО': data.DisplayName, 'ФИО': data.DisplayName })).show(); td.addClass('shown'); } }, }); }); }); What am I doing wrong? And also, for some reason, here it is var id = $('#idrow').attr('data-assigned-id'); I get the wrong data. But this is probably the second question.
