Last active
March 8, 2017 17:58
-
-
Save nayosx/b6b81276307d7f6afca91a31c8755d94 to your computer and use it in GitHub Desktop.
Semi-async data from server to Datatable plugins 1.10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
This is a another example when use a Datatable add | |
--> | |
<script> | |
var oTable; | |
var t_body; | |
$(function(){ | |
t_body = $('#tabla tbody'); | |
oTable = $("#tabla").DataTable({ | |
'dom': "<'row'<'col-sm-3'l><'col-sm-5'f><'col-sm-4 text-right'B>>"+ | |
"<'row'<'col-sm-12'tr>>" + | |
"<'row'<'col-sm-5'i><'col-sm-7'p>>", | |
'buttons': [ | |
{ | |
text: '<i class="fa fa-plus-square"></i> Crear encuesta', | |
className : 'btn btn-default btn-sm', | |
action: function(e, dt, node, config){ | |
modalEncuesta.modal('show'); | |
}, | |
} | |
], | |
'columns': [ | |
{data: "id"}, | |
{data: "nombre"}, | |
{data: "descripcion"}, | |
{data: "action"} | |
] | |
}); | |
encuestas(); | |
function encuestas() { | |
$.ajax({ | |
url: "URL_TO_SERVERG_GET_JSON", | |
type: 'get', | |
dataType: 'json', | |
beforeSend: function () { | |
pleasewait(); | |
}, | |
success: function (response) { | |
initializeDataTable(response.data); | |
}, | |
error: function () {}, | |
complete: function () { | |
unpleasewait(); | |
} | |
}); | |
} | |
function initializeDataTable(data) { | |
$.each(data, function (i, v) { | |
v.id = i + 1; | |
v.action = "Here some buttons"; | |
oTable.row.add(v); | |
}); | |
oTable.draw(); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment