Created
October 24, 2016 10:41
-
-
Save zopyx/9f00ffa362bbbae93a63edd085b421aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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