Fixes in lists
This commit is contained in:
parent
c30600ab75
commit
263dda4721
1 changed files with 54 additions and 8 deletions
62
ajax_list.js
62
ajax_list.js
|
|
@ -40,6 +40,14 @@ $=jQuery;
|
|||
|
||||
}
|
||||
|
||||
if(!$(this).attr('id')) {
|
||||
|
||||
console.log('You need an id for the table');
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
exclude_list=[];
|
||||
|
||||
if(options.hasOwnProperty("exclude_list")) {
|
||||
|
|
@ -238,6 +246,8 @@ $=jQuery;
|
|||
|
||||
search_all=false;
|
||||
|
||||
search_all_text='';
|
||||
|
||||
search_fields=[];
|
||||
|
||||
//order ASC=0, DESC=1
|
||||
|
|
@ -265,11 +275,11 @@ $=jQuery;
|
|||
|
||||
}
|
||||
|
||||
list_tr='<tr class="row_list"> \
|
||||
<td class="loading_cells" colspan="'+fields.length+'" align="center"><i class="fa fa-refresh fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span></td> \
|
||||
list_tr='<tr class="row_list loading_cells"> \
|
||||
<td colspan="'+fields.length+'" align="center"><i class="fa fa-refresh fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span></td> \
|
||||
</tr>';
|
||||
|
||||
$(this).append(list_tr);
|
||||
/*$(this).append(list_tr);*/
|
||||
|
||||
if(!options.hasOwnProperty("num_elements")) {
|
||||
|
||||
|
|
@ -346,15 +356,22 @@ $=jQuery;
|
|||
|
||||
}
|
||||
|
||||
$(this).find('tr.row_list').remove();
|
||||
|
||||
$(this).append(list_tr);
|
||||
|
||||
|
||||
//In url you can send, begin_page, num_elements for pagination.
|
||||
|
||||
$.ajax({
|
||||
url: options.url,
|
||||
type: 'GET',
|
||||
data: {num_elements: options.num_elements, begin_page: begin_page, order_field: order_field, order: order},
|
||||
data: {num_elements: options.num_elements, begin_page: begin_page, order_field: order_field, order: order, search_all_text: search_all_text},
|
||||
table: this,
|
||||
success: function (data) {
|
||||
|
||||
$(this.table).find('.loading_cells').remove();
|
||||
|
||||
//$(options.loading).hide();
|
||||
|
||||
//console.log(table.options);
|
||||
|
|
@ -363,8 +380,6 @@ $=jQuery;
|
|||
|
||||
var z=0;
|
||||
|
||||
$(this.table).find('tr.row_list').remove();
|
||||
|
||||
for (const row of data.items) {
|
||||
//console.log(element);
|
||||
|
||||
|
|
@ -415,6 +430,7 @@ $=jQuery;
|
|||
options.success(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
|
|
@ -426,11 +442,23 @@ $=jQuery;
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
if(search_all) {
|
||||
|
||||
//Add input event to search when search is done
|
||||
|
||||
var search_input='#'+$(this.table).attr('id')+'_search_in_table';
|
||||
|
||||
$(search_input).on('input', {table: this.table}, update_list_search);
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
error: function (data) {
|
||||
|
||||
$(options.loading).hide();
|
||||
//$(options.loading).hide();
|
||||
$(this).find('.loading_cells').remove();
|
||||
|
||||
alert('Error: '+data.status+' '+data.statusText);
|
||||
|
||||
|
|
@ -518,8 +546,26 @@ $=jQuery;
|
|||
if(search_all) {
|
||||
|
||||
console.log('Search all...')
|
||||
//$(this).insertBefore('<p class=""><label for="'+$(this).attr('id')+'_search_in_table">Search:</label><input type="search" name="search_in_table" id="'+$(this).attr('id')+'_search_in_table" /></p>');
|
||||
|
||||
$('<p class=""><label for="'+$(this).attr('id')+'_search_in_table">Search:</label> <input type="search" id="'+$(this).attr('id')+'_search_in_table" placeholder="Search in all fields"/></p>').insertBefore($(this));
|
||||
//console.log($(this).attr('id'));
|
||||
|
||||
//$(form).find(".input_performance").on('keyup', function (e) {
|
||||
|
||||
function update_list_search(e) {
|
||||
|
||||
var search_input='#'+$(e.data.table).attr('id')+'_search_in_table';
|
||||
|
||||
$(search_input).off();
|
||||
|
||||
search_all_text=$(this).val();
|
||||
|
||||
e.data.table.updateAjaxList();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//$('#'+$(this).attr('id')+'_search_in_table').on('input', {table: this}, update_list_search);
|
||||
}
|
||||
|
||||
//First loading of list
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue