Skip to content

Commit

Permalink
datatable: put javascript *after* table dom nodes: maybe some browser…
Browse files Browse the repository at this point in the history
…s trigger

initialization code too early
  • Loading branch information
Bertrand Mathieu committed Feb 21, 2013
1 parent 75c3fe6 commit e4eab76
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
72 changes: 36 additions & 36 deletions yaka/templates/widgets/render_ajax_table.html
@@ -1,39 +1,3 @@
<script>
$(document).ready(function() {

var tbl = $("#{{ view.name }}").dataTable({{ datatable_options|tojson|safe }});

/* export button: setup url args on click, to match current table filtering */
tbl.bind('xhr', $.fn.dataTableSetExportArgs);
$('.btn.datatable-export').click(
{ 'table': tbl.get(0) },
function(e) {
var tbl = e.data.table;
var target = $(e.target);
var href = target.attr('href');
var params = $.data(tbl, 'current-query-args');
window.location = href + '?' + $.param(params);
return false;
}
);

$(document).bind("keydown", keyDown);

function keyDown(e) {
var code = e.keyCode;
// Note: we prevent default keyboard action
if (code == 39) {
$("li.next a").click();
return false;
} else if (code == 37) {
$("li.prev a").click();
return false;
}
return true;
}
});
</script>

<form>
{%- if view.show_controls %}
<div class="btn-group">
Expand Down Expand Up @@ -77,4 +41,40 @@
</table>
</form>

<script type="text/javascript">
$(document).ready(function() {

var tbl = $("#{{ view.name }}").dataTable({{ datatable_options|tojson|safe }});

/* export button: setup url args on click, to match current table filtering */
tbl.bind('xhr', $.fn.dataTableSetExportArgs);
$('.btn.datatable-export').click(
{ 'table': tbl.get(0) },
function(e) {
var tbl = e.data.table;
var target = $(e.target);
var href = target.attr('href');
var params = $.data(tbl, 'current-query-args');
window.location = href + '?' + $.param(params);
return false;
}
);

$(document).bind("keydown", keyDown);

function keyDown(e) {
var code = e.keyCode;
// Note: we prevent default keyboard action
if (code == 39) {
$("li.next a").click();
return false;
} else if (code == 37) {
$("li.prev a").click();
return false;
}
return true;
}
});
</script>

<div style="clear: both;"></div>
13 changes: 7 additions & 6 deletions yaka/templates/widgets/render_table.html
@@ -1,10 +1,4 @@
{%- if table %}
<script>
$(document).ready(function() {
{{ js }}
});
</script>

<form>
{%- if view.show_controls %}
<div class="btn-group">
Expand Down Expand Up @@ -58,6 +52,13 @@
</tfoot>
</table>
</form>

<script type="text/javascript">
$(document).ready(function() {
{{ js }}
});
</script>

{%- else %}
No data. {# <a href="new">{{ _("Create new") }}</a>. #}
{%- endif %}
Expand Down

0 comments on commit e4eab76

Please sign in to comment.