forked from open-data/ckanext-canada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wet_datatable.html
129 lines (112 loc) · 4.29 KB
/
wet_datatable.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{% set chromo = h.recombinant_get_chromo(resource_name) %}
{% if chromo.edit_form %}
{% set offset = 2 %}
{% else %}
{% set offset = 1 %}
{% endif %}
<section>
<h2 id="prtable">{{_("Preview")}}</h2>
<table id="dtprv" class="table table-striped"
data-role="table"
data-mode="columntoggle" >
<thead>
<tr class="font-small">
<th scope="col" data-priority="dtprv-1000">{{ _('Select') }}</th>
{% if chromo.edit_form %}
<th scope="col" data-priority="dtprv-999">{{ _('Edit') }}</th>
{% endif %}
{% set magic_priority_no_field_should_be_below = 2 %}
{% for field in ds_fields %}
<th scope="col" data-priority="dtprv-{{
field.priority + magic_priority_no_field_should_be_below
}}">{{field.label}}<span class="sorting-cnt"><span class="sorting-icons"></span></span></th>
{% endfor %}
</tr>
</thead>
<tbody>
</tbody>
</table>
</section>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.1/css/buttons.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js" defer></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.1/js/dataTables.buttons.min.js" defer></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.1/js/buttons.colVis.min.js" defer></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js" defer></script>
<script type="text/javascript">
window.onload = function() {
window.document.body.onload = previewdatatable();
};
function previewdatatable(){
var table = $( '#dtprv' ).DataTable({
"paging": true,
"serverSide": true,
"processing": true,
"ajax": {
"url": "{{ h.url_for(
controller='ckanext.canada.controller:CanadaController',
action='datatable',
resource_name=resource_name,
resource_id=resource_id,
) }}",
"type": "POST"
},
select:{style: 'multi'},
"order": [[1, "asc"]],
columns: [
{"className":"checkboxes","orderable":false,"targets":0},
{% if chromo.edit_form %}
{"className": "bg-info", "orderable": false, "targets": "no-sort"},
{% endif %}
{% for f in chromo.fields %}
{{- "null" if 'preview_class' not in f else
'{"className":"' | safe ~ f['preview_class'] ~ '"}' | safe }}
{%- if not loop.last %},{% endif %}
{% endfor %}],
dom: "Blfrtip",
language:{
search: "Filter:"
},
buttons: [
'colvis',
{extend:"selected",text:"{{_('Edit in Excel')}}",action: function ( e, dt, button, config ){
var form = $('<form>',{
action : "{% url_for 'recombinant_template', dataset_type=dataset_type, lang=h.lang(),owner_org=owner_org %}",
method : "post"
});
form.append($('<input>').attr({
type: 'hidden',
value: "{{resource_name}}",
name: 'resource_name'
}));
form.append($('<input>').attr({
type: 'hidden',
value: {{primary_keys}},
name: 'key_indices'
}));
var pk_cols = {{primary_keys}}.map( function(value) {
return value + {{offset}};
} );
let rows = dt.rows( { selected: true } );
rows.eq(0).each( function ( index ) {
form.append($('<input>').attr({
type: 'hidden',
value: dt.cells( index, pk_cols ).data().toArray(),
name: 'bulk-template'
}));
} );
form.appendTo('body').submit();
}}]
});
table
.on( 'select', function ( e, dt, type, indexes ) {
var checkbox = dt.cell(indexes,0 ).node().getElementsByTagName('INPUT');
checkbox[0].checked = true;
} )
.on( 'deselect', function ( e, dt, type, indexes ) {
var checkbox = dt.cell(indexes,0 ).node().getElementsByTagName('INPUT');
checkbox[0].checked = false;
} );
};
</script>