Lines 502-504
function filterDataTable( table, column, term ){
Link Here
|
502 |
table.search( term ).draw("page"); |
502 |
table.search( term ).draw("page"); |
503 |
} |
503 |
} |
504 |
} |
504 |
} |
|
|
505 |
|
506 |
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { |
507 |
console.warn(message); |
508 |
}; |
509 |
|
510 |
(function($) { |
511 |
|
512 |
$.fn.api = function(options) { |
513 |
var settings = null; |
514 |
if(options) { |
515 |
settings = $.extend(true, {}, dataTablesDefaults, { |
516 |
'deferRender': true, |
517 |
"paging": true, |
518 |
'serverSide': true, |
519 |
'searching': true, |
520 |
'pagingType': 'full', |
521 |
'ajax': { |
522 |
'type': 'GET', |
523 |
'cache': true, |
524 |
'dataSrc': 'data', |
525 |
'beforeSend': function(xhr, settings) { |
526 |
this._xhr = xhr; |
527 |
if(options.embed) { |
528 |
xhr.setRequestHeader('x-koha-embed', Array.isArray(options.embed)?options.embed.join(','):options.embed); |
529 |
} |
530 |
if(options.header_filter && options.query_parameters) { |
531 |
xhr.setRequestHeader('x-koha-query', options.query_parameters); |
532 |
delete options.query_parameters; |
533 |
} |
534 |
}, |
535 |
'dataFilter': function(data, type) { |
536 |
var json = {data: JSON.parse(data)}; |
537 |
if(total = this._xhr.getResponseHeader('x-total-count')) { |
538 |
json.recordsTotal = total; |
539 |
json.recordsFiltered = total; |
540 |
} |
541 |
return JSON.stringify(json); |
542 |
}, |
543 |
'data': function( data, settings ) { |
544 |
var length = data.length; |
545 |
var start = data.start; |
546 |
|
547 |
var dataSet = { |
548 |
_page: Math.floor(start/length) + 1, |
549 |
_per_page: length |
550 |
}; |
551 |
|
552 |
var filter = data.search.value; |
553 |
if (filter != '') { |
554 |
var query_parameters = settings.aoColumns |
555 |
.filter(function(col) { |
556 |
return col.bSearchable && typeof col.data == 'string' |
557 |
}) |
558 |
.map(function(col) { |
559 |
var part = {}; |
560 |
part[!col.data.includes('.')?'me.'+col.data:col.data] = {like: filter+'%'}; |
561 |
return part; |
562 |
}); |
563 |
|
564 |
if(query_parameters.length) { |
565 |
query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:query_parameters); |
566 |
if(options.header_filter) { |
567 |
options.query_parameters = query_parameters; |
568 |
} else { |
569 |
dataSet.q = query_parameters; |
570 |
} |
571 |
} |
572 |
|
573 |
dataSet._match = 'starts_with'; |
574 |
} else { |
575 |
delete options.query_parameters; |
576 |
} |
577 |
|
578 |
if(options.columns) { |
579 |
var order = data.order; |
580 |
order.forEach(function (e,i) { |
581 |
var order_col = e.column; |
582 |
var order_by = options.columns[order_col].data; |
583 |
var order_dir = e.dir == 'asc' ? '+' : '-'; |
584 |
dataSet._order_by = order_dir + (!order_by.includes('.')?'me.'+order_by:order_by); |
585 |
}); |
586 |
} |
587 |
|
588 |
return dataSet; |
589 |
} |
590 |
} |
591 |
}, options); |
592 |
} |
593 |
return $(this).dataTable(settings); |
594 |
}; |
595 |
|
596 |
})(jQuery); |