Here is my HTML which is a partial view,
<table id="table_id" class="table table-inverse">
<thead class="thead-inverse">
<tr>
<th>Select</th>
<th>StructureName</th>
<th>FieldType</th>
<th>DataType</th>
<th>IsHeirarchy</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td><input type="checkbox" /></td>
<td>@item.One</td>
<td>@item.Two</td>
<td>@item.Three</td>
<td>@item.Four</td>
<td><a href="#"> Edit</a></td>
</tr>
}
</tbody>
</table>
I'm initializing DataTable as shown below,
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('#table_id').DataTable();
});
</script>
Above code is working fine and data table is initialized on page load by calling controller method to populate data.
Now, On click event I'm calling ajax method to pass input parameters to load data as shown below,
$(function () {
$('#searchbtn').on('click', function () {
var url = '@Url.Action("LoadGridData", "Home")';
var clientID = $('#Clientdata').val();
var serviceId = $('#SelectService').val();
$.ajax({
type: "GET",
dataType: "html",
success: function (services) {
$('#searchResults').load(url, { intclientId: clientID, intserviceID: serviceId });
$('#table_id').DataTable();
}
});
});
});
Here, while debugging i can see that $('#table_id').DataTable(); DataTable is initialized but its not staying.
Not sure whats happening. Any help appreciated :)
not staying?