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=[];
|
exclude_list=[];
|
||||||
|
|
||||||
if(options.hasOwnProperty("exclude_list")) {
|
if(options.hasOwnProperty("exclude_list")) {
|
||||||
|
|
@ -238,6 +246,8 @@ $=jQuery;
|
||||||
|
|
||||||
search_all=false;
|
search_all=false;
|
||||||
|
|
||||||
|
search_all_text='';
|
||||||
|
|
||||||
search_fields=[];
|
search_fields=[];
|
||||||
|
|
||||||
//order ASC=0, DESC=1
|
//order ASC=0, DESC=1
|
||||||
|
|
@ -265,11 +275,11 @@ $=jQuery;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list_tr='<tr class="row_list"> \
|
list_tr='<tr class="row_list loading_cells"> \
|
||||||
<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> \
|
<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>';
|
</tr>';
|
||||||
|
|
||||||
$(this).append(list_tr);
|
/*$(this).append(list_tr);*/
|
||||||
|
|
||||||
if(!options.hasOwnProperty("num_elements")) {
|
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.
|
//In url you can send, begin_page, num_elements for pagination.
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: options.url,
|
url: options.url,
|
||||||
type: 'GET',
|
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,
|
table: this,
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
|
||||||
|
$(this.table).find('.loading_cells').remove();
|
||||||
|
|
||||||
//$(options.loading).hide();
|
//$(options.loading).hide();
|
||||||
|
|
||||||
//console.log(table.options);
|
//console.log(table.options);
|
||||||
|
|
@ -363,8 +380,6 @@ $=jQuery;
|
||||||
|
|
||||||
var z=0;
|
var z=0;
|
||||||
|
|
||||||
$(this.table).find('tr.row_list').remove();
|
|
||||||
|
|
||||||
for (const row of data.items) {
|
for (const row of data.items) {
|
||||||
//console.log(element);
|
//console.log(element);
|
||||||
|
|
||||||
|
|
@ -416,6 +431,7 @@ $=jQuery;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
|
@ -427,10 +443,22 @@ $=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) {
|
error: function (data) {
|
||||||
|
|
||||||
$(options.loading).hide();
|
//$(options.loading).hide();
|
||||||
|
$(this).find('.loading_cells').remove();
|
||||||
|
|
||||||
alert('Error: '+data.status+' '+data.statusText);
|
alert('Error: '+data.status+' '+data.statusText);
|
||||||
|
|
||||||
|
|
@ -518,8 +546,26 @@ $=jQuery;
|
||||||
if(search_all) {
|
if(search_all) {
|
||||||
|
|
||||||
console.log('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
|
//First loading of list
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue