I am working on ASP.Net MVC application. I am using jquery datatables.net to show records in form of Grid.
I have a controller with Index IActionItem method, Insert IActionItem method (button outside of jquery datatables.net), Edit IActionItem method (button inside of jquery datatables.net), and Delete IActionItem method (button inside of jquery datatables.net)
When user Add a row or Update any row in jQuery datatables.net, the datatables row shall be highlighted with green background color to let user know that they have added/updated the particular row, upon click of Save button.
The highlighted green background color shall remove, once any other event occurs in the screen.
I have searched a lot for this requirement but couldn't get any proper solution for it.
Please let me know how to achieve it in jQuery datatable.net.
Index.cshtml:
<a class="btn dxButton float-right" asp-area="" asp-controller="MappingWell" asp-action="Well">Add New</a>
<table id="DT_grdMappingWell" class="display table table-bordered table-striped table-hover" style="width:100%">
<thead>
<tr>
<th>Id</th>
<th>MappingId</th>
<th>Study</th>
<th>Scenario</th>
<th>Fpd Well</th>
<th>Aggregation</th>
<th>Project</th>
<th>Pearl Well</th>
<th>Edit</th>
</tr>
</thead>
</table>
@section Scripts{
<script type="text/javascript">
var gridDataOperation;
var grdTable;
$(document).ready(function () {
GetGridData("", "", "");
bindGrid(gridDataOperation);
})
//--grid filter code
function GetGridData(study, scenario, project) {
var actionUrl = "@Url.Action("BindAndFilterGridData", "MappingWell")";
$.ajax({
url: actionUrl,
type: 'GET',
dataType: 'json',
async: false,
cache: false,
data: { study: study, scenario: scenario, project: project },
success: function (responseData) {
gridDataOperation = responseData;
console.log(responseData);
},
error: function (xhr, ajaxOptions, thrownError) {
},
beforeSend: function (jqXHR, settings) {
},
complete: function (jqXHR, textStatus) {
},
});
}
function bindGrid(gridData) {
grdTable = $('#DT_grdMappingWell').DataTable({
data: gridData,
order: [[1, "desc"]],
columns: [
{ title: "Id", data: 'id', "autoWidth": true },
{ title: "MappingId", data: 'mappingId', "autoWidth": true },
{ title: "Study", data: 'studyName', "autoWidth": true },
{ title: "Scenario", data: 'combinedName', "autoWidth": true },
{ title: "Fdp Well", data: 'wellName', "autoWidth": true },
{ title: "Aggregation", data: 'aggregation', "autoWidth": true },
{ title: "Project", data: 'projectName', "autoWidth": true },
{ title: "Pearl Well", data: 'pearlWell', "autoWidth": true }
],
columnDefs: [
{
//hiding the Primary key of the table and also unsearchable.
targets: [0],
visible: false,
searchable: false
},
{
//hiding the mapping_id and also unsearchable.
targets: [1],
visible: false,
searchable: false
},
{
targets: [8],
width: "20",
orderable: false,
render: function (data, type, row) {
return '<a href = "@Url.Action("Update", "MappingWell")?id=' + row.id + '&mappingId=' + row.mappingId + '"><span style="cursor:pointer;">Edit</span></a> ';
}
},
],
});
}
</script>
}
Thank you in advance.