select all problem
select all problem
so I will post my codes step by step:
1.js:
<script>
var pageNumber = 1; // Initial page number
var pageSize = 30; // Initial page size
function getUserFilterData() {
var data = $("#userFilter").serialize();
var searchInputValue = $("#searchInput").val();
// Append search input value, pageNumber, and pageSize to the serialized data
data += "&searchInput=" + searchInputValue + "&pageNumber=" + pageNumber + "&pageSize=" + pageSize;
$.ajax({
type: 'POST',
url: '@Url.Action("FilterUsers", "Notification")',
data: data,
success: function (result) {
if (result.success) {
var dataset = [];
$('#filteredUserList').DataTable().destroy();
$(".dataTables_empty").remove();
result.data.forEach(function (item, index) {
dataset.push([
"<td>" + "<input type='checkbox' value='" + item.userName + "'>" + "</td>",
item.name,
item.surname,
item.userName
]);
});
$('#filteredUserList').DataTable({
dom: 'frt<"clearfix">ip', // Remove default buttons
responsive: true,
paging: false, // Disable pagination
searching: false, // Disable search
"language": {
"emptyTable": "Tabloda herhangi bir veri mevcut değil",
"infoEmpty": "Kayıt yok",
"lengthMenu": "Sayfada _MENU_ kayıt göster",
},
data: dataset
});
// Hide DataTable search input
$('.dataTables_filter input').addClass('hidden');
} else {
alert(result.message);
}
}
});
}
$("#userFilter").submit(function (event) {
event.preventDefault();
pageNumber = 1; // Reset page number to 1 when filtering
getUserFilterData();
});
// Example: Next Page Button
$('#next').click(function () {
pageNumber++;
getUserFilterData();
});
// Example: Previous Page Button
$('#previous').click(function () {
if (pageNumber > 1) {
pageNumber--;
getUserFilterData();
}
});
// Additional button for dynamic page size
$('#setPageNumberBtn').click(function () {
var newNumber = parseInt($('#pageNumberInput').val());
if (!isNaN(newNumber) && newNumber > 0) {
pageNumber = newNumber;
getUserFilterData();
} else {
alert('Please enter a valid positive number for the page number.');
}
});
</script>
public OperationResult<AppUser> FilterUsers(UserFilterRequest userFilter, int pageNumber, int pageSize,string searchInput)
{
try
{
if (userFilter.MinAge > userFilter.MaxAge)
return new OperationResult<AppUser>(OperationResultType.ERROR, "Minimum yaş daha büyük olamaz!", Resource.FailedOR) { EntityDto = null };
if (userFilter.BirthdayRangeFirstDate > userFilter.BirthdayRangeLasttDate)
return new OperationResult<AppUser>(OperationResultType.ERROR, "Doğum tarih aralığı girişinde ilk tarih son tarihten daha büyük olamaz!", Resource.FailedOR) { EntityDto = null };
if (userFilter.MembershipRangeFirstDate > userFilter.MembershipRangeLastDate)
return new OperationResult<AppUser>(OperationResultType.ERROR, "Üyelik tarih aralığı girişinde ilk tarih son tarihten daha büyük olamaz!", Resource.FailedOR) { EntityDto = null };
var maxDate = DateTime.Now.AddYears(-userFilter.MaxAge);
var minDate = DateTime.Now.AddYears(-userFilter.MinAge);
var minAge = userFilter.MinAge;
var maxAge = userFilter.MaxAge;
var users = _userManager.Users
.Where(x => x.ActiveAccount == true
&& (maxAge == 0 || x.BirthDay >= maxDate)
&& (minAge == 0 || x.BirthDay <= minDate)
&& (userFilter.Job == null || userFilter.Job.Count == 0 || userFilter.Job.Contains(x.Job))
&& ((userFilter.Sex == null || userFilter.Sex.Count == 0) || (userFilter.Sex.Count > 1 || userFilter.Sex.Contains(x.Sex)))
&& (userFilter.EducationStatus == null || userFilter.EducationStatus.Count == 0 || userFilter.EducationStatus.Contains(x.EducationStatus))
&& (!userFilter.BirthDayToday || (x.BirthDay.Value.Month == DateTime.Now.Month && x.BirthDay.Value.Day == DateTime.Now.Day))
&& (userFilter.MembershipRangeFirstDate == null || x.CreatedOn >= userFilter.MembershipRangeFirstDate)
&& (userFilter.MembershipRangeLastDate == null || x.CreatedOn <= userFilter.MembershipRangeLastDate)
&& (userFilter.BirthdayRangeFirstDate == null || x.BirthDay >= userFilter.BirthdayRangeFirstDate)
&& (userFilter.BirthdayRangeLasttDate == null || x.BirthDay <= userFilter.BirthdayRangeLasttDate)).OrderBy(x => x.Name)
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize).ToList();
so the problem is when I try to use select all buton it onşy selects the 30 that is on the datatable because of :
1- .Skip((pageNumber - 1) * pageSize)
.Take(pageSize).ToList();
2- var pageNumber = 1; // Initial page number
var pageSize = 30; this part
what I want to do is to get all users when i use select all in this conditions the only thing that i can select is the 30 where pagenumber = 1 2 3 4... is there any way to do it
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Answers
Looks like you are using your own custom table paging solution. You are sending the search and paging parameters to the server using the
data
parameter of jQuery ajax(). I would look at changing what you send to the server to indicate the select all button is clicked and update the server code to fetch all rows. There isn't anything Datatables specific with this solution.Kevin