Subversion-Projekte lars-tiefland.webanos.zeldi.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
4 lars 1
/**
2
 * This pagination plug-in provides pagination controls for DataTables which
3
 * match the style and interaction of the ExtJS library's grid component.
4
 *
5
 *  @name ExtJS style
6
 *  @summary Pagination in the styling of ExtJS
7
 *  @author [Zach Curtis](http://zachariahtimothy.wordpress.com/)
8
 *
9
 *  @example
10
 *    $(document).ready(function() {
11
 *        $('#example').dataTable( {
12
 *            "sPaginationType": "extStyle"
13
 *        } );
14
 *    } );
15
 */
16
 
17
$.fn.dataTableExt.oApi.fnExtStylePagingInfo = function ( oSettings )
18
{
19
	return {
20
		"iStart":         oSettings._iDisplayStart,
21
		"iEnd":           oSettings.fnDisplayEnd(),
22
		"iLength":        oSettings._iDisplayLength,
23
		"iTotal":         oSettings.fnRecordsTotal(),
24
		"iFilteredTotal": oSettings.fnRecordsDisplay(),
25
		"iPage":          oSettings._iDisplayLength === -1 ?
26
 
27
		"iTotalPages":    oSettings._iDisplayLength === -1 ?
28
 
29
	};
30
};
31
 
32
$.fn.dataTableExt.oPagination.extStyle = {
33
 
34
 
35
    "fnInit": function (oSettings, nPaging, fnCallbackDraw) {
36
 
37
        var oPaging = oSettings.oInstance.fnExtStylePagingInfo();
38
 
39
        nFirst = $('<span/>', { 'class': 'paginate_button first' , text : "<<" });
40
        nPrevious = $('<span/>', { 'class': 'paginate_button previous' , text : "<" });
41
        nNext = $('<span/>', { 'class': 'paginate_button next' , text : ">" });
42
        nLast = $('<span/>', { 'class': 'paginate_button last' , text : ">>" });
43
        nPageTxt = $("<span />", { text: 'Page' });
44
        nPageNumBox = $('<input />', { type: 'text', val: 1, 'class': 'pageinate_input_box' });
45
        nPageOf = $('<span />', { text: '/' });
46
        nTotalPages = $('<span />', { class :  "paginate_total" , text : oPaging.iTotalPages });
47
 
48
 
49
        $(nPaging)
50
            .append(nFirst)
51
            .append(nPrevious)
52
            .append(nPageTxt)
53
            .append(nPageNumBox)
54
            .append(nPageOf)
55
            .append(nTotalPages)
56
            .append(nNext)
57
            .append(nLast);
58
 
59
        nFirst.click(function () {
60
            if( $(this).hasClass("disabled") )
61
                return;
62
            oSettings.oApi._fnPageChange(oSettings, "first");
63
            fnCallbackDraw(oSettings);
64
        }).bind('selectstart', function () { return false; });
65
 
66
        nPrevious.click(function () {
67
            if( $(this).hasClass("disabled") )
68
                return;
69
            oSettings.oApi._fnPageChange(oSettings, "previous");
70
            fnCallbackDraw(oSettings);
71
        }).bind('selectstart', function () { return false; });
72
 
73
        nNext.click(function () {
74
            if( $(this).hasClass("disabled") )
75
                return;
76
            oSettings.oApi._fnPageChange(oSettings, "next");
77
            fnCallbackDraw(oSettings);
78
        }).bind('selectstart', function () { return false; });
79
 
80
        nLast.click(function () {
81
            if( $(this).hasClass("disabled") )
82
                return;
83
            oSettings.oApi._fnPageChange(oSettings, "last");
84
            fnCallbackDraw(oSettings);
85
        }).bind('selectstart', function () { return false; });
86
 
87
        nPageNumBox.change(function () {
88
            var pageValue = parseInt($(this).val(), 10) - 1 ; // -1 because pages are 0 indexed, but the UI is 1
89
            var oPaging = oSettings.oInstance.fnPagingInfo();
90
 
91
            if(pageValue === NaN || pageValue<0 ){
92
                pageValue = 0;
93
            }else if(pageValue >= oPaging.iTotalPages ){
94
                pageValue = oPaging.iTotalPages -1;
95
            }
96
            oSettings.oApi._fnPageChange(oSettings, pageValue);
97
            fnCallbackDraw(oSettings);
98
        });
99
 
100
    },
101
 
102
 
103
    "fnUpdate": function (oSettings, fnCallbackDraw) {
104
        if (!oSettings.aanFeatures.p) {
105
            return;
106
        }
107
 
108
        var oPaging = oSettings.oInstance.fnExtStylePagingInfo();
109
 
110
        /* Loop over each instance of the pager */
111
        var an = oSettings.aanFeatures.p;
112
 
113
        $(an).find('span.paginate_total').html(oPaging.iTotalPages);
114
        $(an).find('.pageinate_input_box').val(oPaging.iPage+1);
115
 
116
        $(an).each(function(index,item) {
117
 
118
            var $item = $(item);
119
 
120
            if (oPaging.iPage == 0) {
121
                var prev = $item.find('span.paginate_button.first').add($item.find('span.paginate_button.previous'));
122
                prev.addClass("disabled");
123
            }else {
124
                var prev = $item.find('span.paginate_button.first').add($item.find('span.paginate_button.previous'));
125
                prev.removeClass("disabled");
126
            }
127
 
128
            if (oPaging.iPage+1 == oPaging.iTotalPages) {
129
                var next = $item.find('span.paginate_button.last').add($item.find('span.paginate_button.next'));
130
                next.addClass("disabled");
131
            }else {
132
                var next = $item.find('span.paginate_button.last').add($item.find('span.paginate_button.next'));
133
                next.removeClass("disabled");
134
            }
135
        });
136
    }
137
};