showing results for - "select2 ajax calls 2csorting 2cfiltering data server side in jquery"
Lennard
23 Jul 2016
1var global_data_Store=null;
2			$(".selectpicker").select2({
3				placeholder: '	Select a Parent Group	',
4				//minimumInputLength: 2,
5				language: "en",
6				ajax: { 
7				url: "https://dev1.owlapplicationbuilder.com/appsbuilder/objectsbuilder/api/v1/workflow/metaNew",
8				type: "GET",
9				dataType: 'json',
10				delay: 250,
11				allowClear: true, 
12				matcher: function(term, text, option) {
13					debugger
14					return text.toUpperCase().indexOf(term.toUpperCase())>=0 || option.val().toUpperCase().indexOf(term.toUpperCase())>=0;
15				},
16				data: function (params) {
17					return {
18						searchTerm: params.term// search term
19					};
20				},
21				processResults: function (response) {
22						debugger
23						var obj=response.apiMetaInfo;
24						global_data_Store=response.apiMetaInfo;
25
26						var search=$(".select2-search__field").val();
27						if(search!=="" && search!==null && search!==undefined){
28							debugger;
29							var result_filter=null
30							 result_filter=global_data_Store.filter(function(item) {
31									return item.name.toLowerCase().indexOf(search) > -1
32								});
33							debugger;
34							return {
35								results: $.map(result_filter, function (item) {
36									return {
37										text: item.name,
38										id: item._id
39									}
40								})
41							};
42						}
43						else{
44							return {
45								results: $.map(obj, function (item) {
46									return {
47										text: item.name,
48										id: item._id
49									}
50								})
51							};
52						}
53				},
54				cache: true
55				},
56				dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
57				escapeMarkup: function (m) {
58					 return m; 
59				},
60				sorter: function(data) {
61						return data.sort(function(a, b) {
62							return a.text < b.text ? -1 : a.text > b.text ? 1 : 0;
63						});
64					},
65			});
similar questions