I am using GridMvc to show data from database. GridMvc provide filter and sorting grid which is very useful. But now I meet a problem: I want to use JQuery to get a list of id attributes and pass this list to backend. But the Grid is Paged with 30 records per page. So I can only get a list of 30 ids from Page 1. Here is the paged grid:
What I want to do is get all href values(e.g. get a list of XX from page div). And when user trigger Export button, I define an JS Export function:
$('#Export').click(function () {
//Todo: Select all data from front end. Send a list to backend.
var Items = new Array();
var hrefs = new Array();
$('.pagination li').each(function () {
hrefs.push($(this).find('a').attr('href'));
});
var i = 0;
//var items = DeleteItems();
while (i < hrefs.length) {
//redirected to different pages
document.location.href = '/GridView' + hrefs[i];
//Save data
$('#PCA-grid table').find('.grid-row').each(function (index, item) {
//Find target items
var id;
var $checkbox = $(this).find('.DeleteSelected:first');
//Set a for loop here to
if (!$checkbox.is(':checked')) {
id = Number($checkbox.attr('id'));
if (id != NaN) {
Items.push(id);
}
}
});
i++;
}
//Sent list of ids to backend. Using URL redirect
window.location.replace('/GridView/Export?items=' + Items);
});
The basic thought has been described in code above. What I want to do is get urls from page tag. In while loop, try to redirect to target page and then push id attributes in this page to Items Array. But when I debut using Chrome tool, the while loop is not working as expected. There is no redirection happens.
Am I wrong with this problem? I just want to get id attributes from all pages in current grid and then pass this Items Array to backend. So anyone help me?
As far as I considered, it's hard to get all id attributes that needed to be downloaded with paging in grid. What I did was redirecting page to another view. In that view, I hidden same grid with no paging. And sent ids needed to be downloaded from grid to backend, then generated file for client user.
Not sure whether this way is best practice. But I used this method solved this problem.