I am create one small demo for show users list.for that show list used datatabel with angularjs. my listing show very well first time.but i want to create custom filter on that tabel.i want to get pass week data and i have return query also in controller and data getting propare but i don't know how to next time bind datatable in angularjs.
here first time bind datatable code:
app.controller('userscontroller', ['$scope', '$http', 'DTOptionsBuilder', 'DTColumnBuilder',
function ($scope, $http, DTOptionsBuilder, DTColumnBuilder) {
$scope.dtColumns = [
//DTColumnBuilder.newColumn("id", "User ID"),
DTColumnBuilder.newColumn("firstname", "First Name"),
DTColumnBuilder.newColumn("lastname", "Last Name"),
DTColumnBuilder.newColumn("email", "Email"),
]
debugger;
$scope.dtOptions = DTOptionsBuilder.newOptions().withOption('ajax', {
url: "/api/User/GetUserList",
type: "GET",
data: { 'searchRequest': null, fromDate: null, toDate: null },
contentType: "application/json; charset=utf-8",
})
.withPaginationType('full_numbers')
.withDisplayLength(50);
}])
this is my controller method:
[HttpGet]
[Route("GetUserList")]
public IHttpActionResult GetUserList(string searchRequest)
{
var UserList = db.UserInfo.ToList();
if (searchRequest != null)
{
if (searchRequest == "Past Week")
UserList = UserList.Where(t => Convert.ToDateTime(t.registrationdate).ToString("MMM dd yyyy") == DateTime.Now.AddDays(-7).ToString("MMM dd yyyy")).ToList();
}
var Details = UserList.Select(h => new
{
h.id,
h.firstname,
h.lastname,
h.registrationdate,
h.email,
h.contactnumber
});
return Json(Details);
}
this is my code for select past year data:
$scope.GetValue = function (event) {
var Type = $scope.ddlSearch;
$.ajax({
type: "GET",
cache: false,
url: '/api/User/GetUserList',
data: { searchRequest: Type },
success: function (response) {
}
});
this is my table html :
<table id="entry-grid" datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="table table-hover"> </table>
i have try this code but i don't know how to reload datatable in anuglarjs.any one know then please help me for this task.