Although paging is covered in the ldapjs documentation, I'm unclear on how to implement paging in my application using an ajax client. Let's say I make a simple call to the server to search the LDAP for all people in the organization, initially for the first page with 10 entries, like this:
$.ajax({
method: "GET",
url: "LDAPSearch",
data: {
filter: "(ou=People)",
pageNum: 1,
entriesPerPage: 10
}
}).done(function( result ) {
console.log('result: ', result);
});
I would expect the server to send back a result containing the first 10 entries as well as the total number of entries that the search yielded so that I know how many pages there will be. In the ldapjs code on the server, I would expect a parameter in the opts for pageNum, such as:
var opts = {
filter: '(objectclass=commonobject)',
scope: 'sub',
paged: true,
pageNum: 1, //This is not a valid option, but how I would expect it to work
sizeLimit: 10
};
client.search('o=largedir', opts, function(err, res) {
assert.ifError(err);
res.on('searchEntry', function(entry) {
// do per-entry processing
});
res.on('page', function(result) {
console.log('page end');
});
res.on('error', function(resErr) {
assert.ifError(resErr);
});
res.on('end', function(result) {
console.log('done ');
});
});