Custom spreadsheet search

Jexcel Spreadsheet Pro v7.7.1+ brings two new events onbeforesearch and onsearch. It is possible, using the event onbeforesearch to intercept the search, cancel or apply a different algorithm to customize the results to the user. In the following example, the event will cancel the native method, trigger an ajax request to query the results in the backend.

How to process a search in the backend

<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href="" type="text/css" />
<link rel="stylesheet" href="" type="text/css" />

<div id="spreadsheet"></div>

var table = jexcel(document.getElementById('spreadsheet'), {
    csv: '/jexcel/demo.csv',
    csvHeaders: true,
    search: true,
    pagination: 10,
    paginationOptions: [10,25,50,100],
    defaultColWidth: 100,
    onbeforesearch: function(el, str, currentResults) {
        // Loading spin;
        // Remote search processing
            url: '/v7/search',
            dataType: 'json',
            success: function(newResults) {
                // Set the rowIds that should be return to the user.
                // For this example the return will be [5,21]
                el.jexcel.results = newResults;
                // Execute the update
                // Loading spin

        // Cancel the native search
        return false;

Onbeforesearch signature

onbeforesearch(DOMElement el, String str, Array rowNumbers, Object search) => arrayWithResults

// The return should be an array with rowNumbers.
// In the following example the spreasheed will show three records.
// It is possible to cancel the search by return === false

return [10,99,1355]; 
Argument description
el The Jexcel DOM container.
str The string used by the user
rowNumbers The current results, which can be intercepted and overwrite
search The object with the search handler methods

Related events

Events Description
onbeforesearch onbeforesearch(DOMElement el, String str, Array rowNumbers, Object search)
Action to be executed before the search. It can be used to cancel or to intercept and customize the searching process.
onsearch onbeforesearch(DOMElement el, String str, Array rowNumbers, Object search)
After the search process is completed.
onchangepage onchangepage(DOMElement el, Number pageNumber, Number oldPage, Number quantityPerPage)
Action to be executed before the page changes. It can cancel the action by returning false.
onpage onpage(DOMElement el, Number quantityPerPage, Number oldPage, Number pageNumber)
After the page has changed.

Related methods

Method Description
page pageNumber)
Go to the page number.
whichPage table.whichPage()
Return the current page.
quantiyOfPages table.quantiyOfPages()
Get the quantity of pages.