Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
924 B
1
Indexable
Never
$('#global_project_id').select2({
    placeholder: "Select Project",
    allowClear: true,
    cache: false,
    ajax: {
        url: "{{route('searchProjects')}}",
        dataType: 'json',
        delay: 300,
        minimumInputLength: 3,
        data: function(params) {
            return {
                search: params.term,
                page: params.page,
            };
        },
        processResults: function(data, params) {
            params.page = params.page || 1;
            
            return {
                results: data.results.data.map(function(item) {
                    
                    return {
                        id : item.id,
                        text : item.name,
                    }; 
                }),
                pagination: {
                    more: ((params.page * 20) < data.results.total) ? true : false
                }
            };
        }
    }
});