Skip to content

Instantly share code, notes, and snippets.

@zopyx
Created October 24, 2016 10:41
Show Gist options
  • Save zopyx/9f00ffa362bbbae93a63edd085b421aa to your computer and use it in GitHub Desktop.
Save zopyx/9f00ffa362bbbae93a63edd085b421aa to your computer and use it in GitHub Desktop.
function do_search(query) {
$('#material-slot').html('');
var tree = $("#warengruppen-tree").fancytree("getTree");
var rex = new RegExp(query, "i");
var found = [];
var hits = tree.filterNodes(
function(node) {
var matches = rex.test(node.data.searchable_text);
if (matches) {
found.push({materialnr: node.data.num, kreditor_sap_id: node.data.kreditor_sap_id});
}
return matches;
},
{autoExpand: true, leavesOnly: false});
/* update counter in UI */
$('#num-hits').text(hits + ' Treffer');
$.ajax({
type: 'POST',
url: 'webshop-materialien',
data: JSON.stringify({'materialnummern': found}),
contentType: 'application/json',
success: function(data) {
$('#material-slot').html(data);
}
});
}
function clear_search() {
var tree = $("#warengruppen-tree").fancytree("getTree");
tree.clearFilter();
tree.visit(function(node){
node.setExpanded(false);
});
$('#num-hits').text('');
$('#material-slot').html('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment