View | Details | Raw Unified | Return to bug 20212
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-1 / +68 lines)
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
- 
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
                            },
531
                            'dataFilter': function(data, type) {
532
                                var json = {data: JSON.parse(data)};
533
                                if(total = this._xhr.getResponseHeader('x-total-count')) {
534
                                    json.recordsTotal = total;
535
                                    json.recordsFiltered = total;
536
                                }
537
                                return JSON.stringify(json);
538
                            },
539
                            'data': function( data, settings ) {
540
                                var length = data.length;
541
                                var start  = data.start;
542
543
                                var dataSet = {
544
                                    _page: Math.floor(start/length) + 1,
545
                                    _per_page: length
546
                                };
547
548
                                var filter = data.search.value;
549
                                if (filter != '') {
550
                                    dataSet.name = filter;
551
                                    dataSet._match = 'starts_with';
552
                                }
553
554
                                if(options.columns) {
555
                                    var order = data.order;
556
                                    order.forEach(function (e,i) {
557
                                        var order_col      = e.column;
558
                                        var order_by       = options.columns[order_col].data;
559
                                        var order_dir      = e.dir == 'asc' ? '+' : '-';
560
                                        dataSet._order_by = order_dir + order_by;
561
                                    });
562
                                }
563
564
                                return dataSet;
565
                            }
566
                        }
567
                    }, options);
568
        }
569
        return $(this).dataTable(settings);
570
    };
571
572
})(jQuery);

Return to bug 20212