i use data table with django and jquery .....
in my case i have the index.html and other file with my tbody...
when i insert one record in database i reload all records and return json , in this json i have my tbody with all my records
and others informations...
i render in my htm on page this way
$('#license_table tbody').html(data.table_license);
but the parameter than define not work i try the function .draw() but not work ? ,
can't apply initial parameter dynamically ?
the parameter just set if i reload the page...
if i use .draw , when update or delete record my table not updated if remove this function,
my table updated, but when is update i lost the parameter values initials
how i can just reload the setting of the datatable...
i'm a backend beginner , so sory if a little confuse...
my initial parameter:
var table = $('#license_table').DataTable({
"order": [[ 0, "desc" ]],
"pageLength": 5,
"lengthMenu": [3, 5, 10, 25, 50, 75, 100 ],
"language": {
"lengthMenu": " MENU registros por pagina",
"zeroRecords": "Nenhum registro encontrado, desculpe",
"info": "PAGE de PAGES",
"infoEmpty": "sem registros ",
"infoFiltered": "(filtro de MAX total )"
},
"language": {
"Search": "Pesquisar ",
"lengthMenu": "Mostrar MENU registro por paginas",
"zeroRecords": "não há registros",
"info": "Mosnrando registro PAGE de PAGES",
"infoEmpty": "Nenhum resuldado foi encontrado",
"infoFiltered": "(filtradno de MAX total de registros)",
"paginate": {
"next": "Próxima",
"previous": "Anterior"
}
}
});
function i use my ajax....
var saveFormLicense = function(){
var form = $(this);
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
dataType: 'json',
success: function(data){
if(data.is_form_valid){
$('#license_table tbody').html(data.table_license);
$('#modal-license').modal('hide');
$('#js-message').text(data.js_title_message)
$('#js-serial').text(data.js_serial)
$('#js-cliente').text(data.js_cliente)
$('#modal-message').modal('show');
}else{
$('#modal-license .modal-content').html(data.form_html);
}
}
});
// return false because this method is trigger on submit.
return false;
};
my json response
{
"table_license":
"\n\n<tr class=\"\" >\n <td id=\"19\">19</td>\n <td class=\"client_clicked
\">KAREKA TUTTI VIDEO</td>\n <td >78-E7-D1-AD-1E-96</td>\n <td >D1121L</td>\n <td
28/01/2017</td>\n\n <td ><button class=\"btn btn-warning js-license-update\" type=\"button\"
data-url=\"/licenses/update/19/\">\n <span class=\"glyphicon glyphicon-pencil\"> </span>\n
</button></td>\n\n <td ><button class=\"btn btn-danger js-license-delete\" type=\"button
\" data-url=\"/licenses/delete/19/\">\n <span class=\"glyphicon glyphicon-trash\"> </span
\n </button></td>\n </tr>\n\n\n\n<tr class=\"\" >\n <td id=\"16\">16</td>\n
<td class=\"client_clicked\">RRC PREST. DE SERV. POSTAIS S/C LTDA.</td>\n <td >78-E7-D1-AD-1E-96
</td>\n <td >D1019A</td>\n <td >21/01/2017</td>\n\n <td ><button class=\"btn btn-warning
js-license-update\" type=\"button\" data-url=\"/licenses/update/16/\">\n <span class=\"glyphicon
glyphicon-pencil\"> </span>\n </button></td>\n\n <td ><button class=\"btn btn-danger js-license-delete
\" type=\"button\" data-url=\"/licenses/delete/16/\">\n <span class=\"glyphicon glyphicon-trash
\"> </span>\n </button></td>\n </tr>\n\n\n\n<tr class=\"\" >\n <td id=\"18\">18</td
\n <td class=\"client_clicked\">KAREKA TUTTI VIDEO</td>\n <td >78-E7-D1-AD-1E-96</td>
\n <td >D1019C</td>\n <td >14/01/2017</td>\n\n <td ><button class=\"btn btn-warning
js-license-update\" type=\"button\" data-url=\"/licenses/update/18/\">\n <span class=\"glyphicon
glyphicon-pencil\"> </span>\n </button></td>\n\n <td ><button class=\"btn btn-danger js-license-delete
\" type=\"button\" data-url=\"/licenses/delete/18/\">\n <span class=\"glyphicon glyphicon-trash
\"> </span>\n </button></td>\n </tr>\n\n\n\n<tr class=\"\" >\n <td id=\"20\">20</td
\n <td class=\"client_clicked\">IFACE LTDA</td>\n <td >78-E7-D1-AD-1E-96</td>\n
<td >DE726H</td>\n <td >14/01/2017</td>\n\n <td ><button class=\"btn btn-warning js-license-update
\" type=\"button\" data-url=\"/licenses/update/20/\">\n <span class=\"glyphicon glyphicon-pencil
\"> </span>\n </button></td>\n\n <td ><button class=\"btn btn-danger js-license-delete
\" type=\"button\" data-url=\"/licenses/delete/20/\">\n <span class=\"glyphicon glyphicon-trash
\"> </span>\n </button></td>\n </tr>\n\n\n\n<tr class=\"\" >\n <td id=\"15\">15</td
\n <td class=\"client_clicked\">PENSAO PONTE DA BARCA LTDA.</td>\n <td >78-E7-D1-AD-1E-63
</td>\n <td >DE726A</td>\n <td >05/01/2017</td>\n\n <td ><button class=\"btn btn-warning
js-license-update\" type=\"button\" data-url=\"/licenses/update/15/\">\n <span class=\"glyphicon
glyphicon-pencil\"> </span>\n </button></td>\n\n <td ><button class=\"btn btn-danger js-license-delete
\" type=\"button\" data-url=\"/licenses/delete/15/\">\n <span class=\"glyphicon glyphicon-trash
\"> </span>\n </button></td>\n </tr>\n\n\n\n<tr class=\"\" >\n <td id=\"21\">21</td
\n <td class=\"client_clicked\">MAURICIO MAIMONE FRANCISCO</td>\n <td >78-E7-D1-AD-1E-63
</td>\n <td >D1121O</td>\n <td >05/01/2017</td>\n\n <td ><button class=\"btn btn-warning
js-license-update\" type=\"button\" data-url=\"/licenses/update/21/\">\n <span class=\"glyphicon
glyphicon-pencil\"> </span>\n </button></td>\n\n <td ><button class=\"btn btn-danger js-license-delete
\" type=\"button\" data-url=\"/licenses/delete/21/\">\n <span class=\"glyphicon glyphicon-trash
\"> </span>\n </button></td>\n </tr>\n\n\n\n<tr class=\"\" >\n <td id=\"14\">14</td
\n <td class=\"client_clicked\">SAO FRANCISCO COMER.DE INF.LTDA-ME.</td>\n <td >78-E7-D1-AD-1E-64
</td>\n <td >D1121B</td>\n <td >28/12/2016</td>\n\n <td ><button class=\"btn btn-warning
js-license-update\" type=\"button\" data-url=\"/licenses/update/14/\">\n <span class=\"glyphicon
glyphicon-pencil\"> </span>\n </button></td>\n\n <td ><button class=\"btn btn-danger js-license-delete
\" type=\"button\" data-url=\"/licenses/delete/14/\">\n <span class=\"glyphicon glyphicon-trash
\"> </span>\n </button></td>\n </tr>\n\n",
"js_cliente": "KEFAS COM. IMPOR. E EXPOR. LTDA",
"js_title_message": "Licen\u00e7a Deletada com sucesso!",
"is_form_valid": true,
"js_serial": "DE726B"
}