External column search for DataTables - search

I have a DataTable (1.10.0) running with the help of CodeIgniter. The data is provided by ajax with Datatables library. Everything is running fine.
I would like to insert an input field somewhere on my page to filter/search only one column. I have tried with:
$('#customer').on( 'keyup click', function () {
$('#results').DataTable().search(
$('#customer').val()
).draw();
} );
This searches in all columns, and changes the value in the DataTables' own search field. If I add column(), it will not search in the table anymore, although it draws all ajax data again without filter/search.
$('#customer').on( 'keyup click', function () {
$('#results').DataTable().column(0).search(
$('#customer').val()
).draw();
} );
My question: What is the proper way to implement external column search/filter on server-side processed data?
Thanks!

You are using column().search() API function correctly.
However with server-side processing, individual column searches are sent in separate request parameters, see Server-side processing.
For example, if you search the first column with value John Doe, your server side script will receive a request with parameter columns[0][search][value] set to John Doe while global search parameter search[value] would be empty.
You need to handle this individual column searches separately on the server-side, either manually or with help of a library.

Related

NodeJS Express pagination with Google Datastore how to integrate cursor queries with UI control

I am stuck on implementing Pagination and I just need a bit of help, either some example code or even just a hint to help me proceed in the right direction.
I'm looking for some guidance on how to integrate Google Datastore database cursors with front-end UI pagination controls. I know how to build an angular pagination service, but that's with retrieving all the data at once and due to performance issues (5,000 records+) I want to use cursors to retrieve data in subsets.
NOTE: There's a similar question here, but I need more detail than this accepted answer provides. Node pagination in google datastore
QUESTION: How can I integrate the paginated datastore cursor queries with the front-end UI controls to allow the user to select the current page and control number of results displayed on each page?
I need to build a page that displays a large number of records with dynamic pagination. The user must be able to select the number of records display on each page.
Since there are several thousand records that might be returned at one time, I want to use cursors to retrieve subsets of data.
There is an example of how to paginate in the docs, but it is a pretty basic example and does not demonstrate how to integrate with front-end UI controls.
Can anyone provide a more detailed example and/or point me in the right direction on where to begin with this requirement? Unfortunately I haven't been able to find any detailed examples online.
https://googlecloudplatform.github.io/google-cloud-node/#/docs/datastore/1.1.0/datastore
Paginating Records
var express = require('express');
var app = express();
var NUM_RESULTS_PER_PAGE = 15;
app.get('/contacts', function(req, res) {
var query = datastore.createQuery('Contacts')
.limit(NUM_RESULTS_PER_PAGE);
if (req.query.nextPageCursor) {
query.start(req.query.nextPageCursor);
}
datastore.runQuery(query, function(err, entities, info) {
if (err) {
// Error handling omitted.
return;
}
// Respond to the front end with the contacts and the cursoring token
// from the query we just ran.
var frontEndResponse = {
contacts: entities
};
// Check if more results may exist.
if (info.moreResults !== datastore.NO_MORE_RESULTS) {
frontEndResponse.nextPageCursor = info.endCursor;
}
res.render('contacts', frontEndResponse);
});
});
One thing to keep in mind is the first item on the Limitations of cursors list:
A cursor can be used only by the same project that performed the original query, and only to continue the same query. It is not
possible to retrieve results using a cursor without setting up the
same query from which it was originally generated.
So you need to always be able to re-create the original query inside your handler, which means you need to pass around the equivalent of your NUM_RESULTS_PER_PAGE value from one request to another. You also need to reset the query every time that value changes - meaning you can't continue browsing from where you were after changing the number of results displayed per page.
Then, to be able to use the pagination, you also need to pass around the current cursor value from one request to another, updated at every request.
Now I'm not a NodeJS user, so I can tell exactly how this passing values around from one request to another would typically be implemented. In your code req.query.nextPageCursor and frontEndResponse.nextPageCursor appear to be intended for this, but I can't tell if that's OK or not. Maybe this is a less specific question easier to find an answer for.
In python webapp2, for example, I can store such values server-side in the user's session in one request and read them from the session in a subsequent request. Donno if this is of any help.

NodeJS - PUG/Express: Display data collected from form

I think of this as a really simple problem, but I'm having a lot of trouble finding a straight answer.
Simple use case:
Form that collects data, but does not save data to any database,
Run calculations on data (some basic math, done through the controller after 'Submit' is clicked).
Display newly calculated data on new page.
I'm having trouble figuring out how to get step 3 working. I've created a route and view, and I'm rendering it on 'Submit'. I just don't know how to use the newly calculated variables from my controller on this new page.
Any help/resources would be greatly appreciated. The end of my controller function looks something like this:
var age_upper = age + 60;
...
res.render('ageResults');
Where 'ageResults' would be the page I want to display the calculated data on.
Pass the values to the template in the 'locals' using:
res.render('ageResults', {age_upper: age_upper})
Then use #{age_upper} in ageResults.pug.

JHipster ComboBox lazyloading

I'm starter to use JHipster. One of my entity A has more than 3000 data. So I used infinite-scroll as pagination. But as relation to another Entry B, it will be generated as a comboBox in the dialog. I got only 20 data in the comboBox. There is no infinit-scroll or search and loading to get more data.
Can someone give any advice to fix the problem?
The infinite scroll uses pages (which is mapped to pageablea in spring). Thus, your service call that fetches the data for the box only fetches the first page. And the default page size is 20. So, you need to increase the page size to get more results.
You can either overwrite the "size" variable or the global constant called "itemsPerPage" which is located in pagination.constants.js
Am I right that it is a one-to-many relationshiop and you want to choose one of 3000 possible A for an entity B?
If so, you don't want to load all 3000 possible As into the dropdown. Therefore, I would replace the dropdown with another input, e.g. the typeahead from angular-ui (https://angular-ui.github.io/bootstrap/#/typeahead), so you can fetch a filtered subset of your entities.
Another way, I also used before, would be a list with a pagination for A that opens in a modal and returns the selected entity that could be passed to b.
Or, if you really want to fetch all: I would add a new endpoint without the pageable, add a new method to the angular-resource-service and call this instead of the paged version.

Parse-Server query fed directly from URL query string

I'd like to know if this is even possible. And if it is possible, what the security ramifications would be.
I want to use Javascript to build a dynamic URL to query a Parse-Server database.
It appears that it might be possible based on an earlier Stackoverflow question here and a Node.js doc here
Here's how I envision it working....
So, a user would be sent (via email/Twitter/etc) a link which was created by above method. Once the user clicked on that URL link, the following would happen automatically:
Step #1: User's system would automatically submit a parse-server query.
Step #2: On success, the user's browser would download a web page which displayed the query results.
step one create the pointer value ie the query pseudo-semantic
step 2 insert the pointer value to a text-type field in parse cls=clazz
step 2b mailgun a msg containing a link like :
express.domain.com/#!clazz/:yALNMbHWoy - where 'yA...oy' is oid of pointer row in parse/clazz table
Note that the link is an abstraction only. Its a uri first to express/route && function that will simply get a row from parse.clazz. That row contains the semantic for making a parse query to get back the full DB compliment to pass along to the node template setting up the html ...
in your node/router GET/clazz/:oid will lookup that Parse row in parse/clazz, using the pointer/text value to format a 2nd, Parse query. The query response from the 2nd parse.qry is your real meat ... This response can be used by the express template formatting the html response to orig request on "express.domain.com".
where u ask "download web page" .. that is simply node's RESPONSE to a GET on a route like "GET/clazz".

How to perform a simple search on Dojo DataGrid

For a project, I had to swictch from DataTable jquery plugin to Dojo.
Dojo is great and everything works fine !
But, I miss the dataTable's simple search form (http://datatables.net/).
I know that Dojo have the Filter plugin which could make that, but it's not simple, for the users, as the dataTable input field (at less two more click for a global search on a table :/).
I search all the web but i couldn't find an exemple with it :/
If someone has a clue ?
This depends on what kind of backend data store you are using to power your grid.
It's usually just a simple matter of calling grid.setQuery({name: "FooBar" , ignoreCase: true });
But lets say you are using an [AndOrReadStore][1], rather than a simple ItemFileReadStore, then you might specify the columsToQuery and the columnValue as well.
Remmber, you always query your grid not the store. The grid will pass the query on to the store.
So, to do what you want, just create a new input on your page. Capture key presses or onchange, and then query your grid accordingly. This will filter results that don't match.
The reason why you might use query, is because if your store is powered from the server, it will make sure to requery the backend.
However, if your grid is entirely loaded in memory, then you can do client side filtering by using filter().

Resources