TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
469.6k
empty record list on your Jquery dataTable
Feb 13 2020 12:42 AM
Hi Team
I am returning an empty record list on my dataTable, what could be an issue? Is the issue on my calling of dbContext not correcttly? Please help me mates as i am returning an empty record list on UI. Here is my logic below for this reason.
[HttpPost]
public
ActionResult GetList() {
//Server side Parameter.
int
start = Convert.ToInt32(Request[
"start"
]);
int
length = Convert.ToInt32(Request[
"length"
]);
string
searchValue = Request[
"search[value]"
];
string
sortColumnName = Request[
"columns["
+ Request[
"order[0][column]"
] +
"][name]"
];
string
sortDirection = Request[
"order[0][dir]"
];
using
(eNtsaOnlineRegistrationDBContext db =
new
eNtsaOnlineRegistrationDBContext()) {
IQueryable < TblEventsManagements > empList = db.TblEventsManagements;
int
totalrows = empList.Count();
int
totalrowsafterfiltering = totalrows;
if
(!
string
.IsNullOrEmpty(searchValue)) {
empList = empList.Where(x => x.TrainingType.Contains(searchValue) || x.TrainingDescription.Contains(searchValue) || x.Price.ToString().Contains(searchValue.ToLower()) ||
x.Venue.Contains(searchValue) || x.Facilitator.Contains(searchValue) || x.WhoAttend.Contains(searchValue) || x.Rsvp.Contains(searchValue));
totalrowsafterfiltering = empList.Count();
}
empList = empList.OrderBy(sortColumnName +
" "
+ sortDirection).Skip(start).Take(length);
return
Json(
new
{
data = empList.ToList(), draw = Request[
"draw"
], recordsTotal = totalrows, recordsFiltered = totalrowsafterfiltering
}, JsonRequestBehavior.AllowGet);
}
}
<script>
$(document).ready(
function
() {
$(
"#EventsManagementsTable"
).DataTable({
"ajax"
: {
"url"
:
"/Dashboard/GetList"
,
"type"
:
"POST"
,
"datatype"
:
"json"
},
"columns"
: [
{
"data"
:
"TrainingType"
,
"name"
:
"TrainingType"
},
{
"data"
:
"TrainingDescription"
,
"name"
:
"TrainingDescription"
},
{
"data"
:
"Price"
,
"name"
:
"Price"
},
{
"data"
:
"Venue"
,
"name"
:
"Venue"
},
{
"data"
:
"Facilitator"
,
"name"
:
"Facilitator"
},
{
"data"
:
"WhoAttend"
,
"name"
:
"WhoAttend"
},
{
"data"
:
"RSVP"
,
"name"
:
"RSVP"
},
],
"serverSide"
:
"true"
,
"order"
:[0,
"asc"
],
"processing"
:
"true"
,
"language"
: {
"processing"
:
"processing... please wait"
}
});
});
</script>
Reply
Answers (
9
)
How to filter out search using server side processing?
asp.net html to pdf downloding.