Pass data value to ajax request - DataTables 1.10.0

Pass data value to ajax request - DataTables 1.10.0

APoncianoAPonciano Posts: 4Questions: 1Answers: 0

Hi,
I'm missing something here and would appreciate the help. I need to send a information to my server page using AJAX data, but i just can't manage. I tried all the examples in (http://datatables.net/reference/option/ajax) with out success. can some one PLEASE send an example. What I need to achieve is something like this:

    "ajax": {
        "url": rootUrl + "Usuario/listAll",
        "type": "POST",
        "data": {"MYINFO":"Value"}
      },

Thanks for the help>

Answers

  • APoncianoAPonciano Posts: 4Questions: 1Answers: 0
    edited June 2014

    Just adding my entire configuration for datatables.

    var t = $('#datatable').dataTable( {
    "oTableTools": {
    "sSwfPath": "js/jquery.datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf",
    "sTitle":"Usuarios",
    "aButtons": [
    {
    "sExtends": "text",
    "sButtonText": 'Novo',
    "fnClick": function( nButton, oConfig ) {
    console.log('novo registro');
    $('#legendaModal').text('Novo Usuário');
    $("#formulario")[0].reset();
    $("#inputIdUsuario").val("");
    $("#errorServer").html("");
    $("#errorServer").hide();
    $("#errorEmpty").hide();
    $("#novoModal").niftyModal('show');
    }
    },
    {
    "sExtends": "collection",
    "sButtonText": 'Exportar <span class="caret" />',
    "aButtons": [ "copy", {
    "sExtends": "xls",
    "sFileName": "Usuario - *.xls"
    }, {
    "sExtends": "pdf",
    "sFileName": "Usuario - *.pdf"
    },"print" ]
    },
    {
    "sExtends": "text",
    "sButtonText": 'Mostrar bloqueados',
    "sButtonClass" : "toggle-row-display",
    "fnClick": function( nButton, oConfig ) {
    console.log('Mostrat Todos');
    $(nButton).toggleClass('selected');
    }
    }
    ],
    "fnRowSelected": function ( nodes ) {
    alert( 'The row with ID '+nodes[0].id+' was selected' );
    },
    },
    "sDom": 'T<"clear">lfrtpi',
    "autoWidth": false,
    "language": {
    "lengthMenu": "Mostrar _MENU_ registros por página",
    "zeroRecords": "Nenhum registro localizado - desculpe",
    "info": "Mostrando página _PAGE_ de _PAGES_",
    "infoEmpty": "Sem registros",
    "emptyTable": "Sem registros para visualizar" ,
    "infoFiltered": "(filtrando _MAX_ do total de registros)",
    "search": "Procurar: ",
    "loadingRecords": "Por gentileza aguarde - CARREGANDO...",
    paginate: {
    first: "Primeiro",
    previous: "Anterior",
    next: "Próximo",
    last: "Último"
    },

        },
        "ajax": {
            "serverSide": true,
            "url": rootUrl + "Usuario/listAll",
            "type": "POST",
            "data": {"IDMenu": "1"},
          },
          "columnDefs": [
                       { "orderable": false, "targets": [5,6,7,8] },
                      // { "targets": [ 8 ], "visible": false},
    
                     ],
          "columns": [
                      { "data": "NomeUsuario" },
                      { "data": "Email" },
                      { "data": "Codigo" },
                      { "data": "Descricao" },
                      { "data": "ultLogin" },
                      { "data": "Col5" },
                      { "data": "Col6" },
                      { "data": "Col7" },
                      { "data": "Col8" },
                  ],
          "rowCallback": function( row, data ) {                    
                    if(data['Ativo'] == "1"){
                        tipoCadeado = "fa-unlock";
                        legendaCadeado = "Bloquear Usuário";
                    } else {
                        tipoCadeado = "fa-lock color-warning";
                        legendaCadeado = "Habilitar Usuário";               
                    }
                    if($("#numero").data("numero2") == 1) {
    
                        $('td:eq(5)', row).html("<a title='Alterar Senha' href='#'><i class='fa fa-key' data-idUsuario='" +data['DT_RowId'] + "' data-nome='" + data['DT_RowId'] + "'/></i></a>");
                        $('td:eq(6)', row).html("<a title='Editar' href='#'><i class='fa fa-edit' data-idUsuario='" + data['DT_RowId'] + "' data-nome='" + data['DT_RowId']+ "'/></i></a>");
                        $('td:eq(7)', row).html("<a title='" + legendaCadeado + "' href='#'><i class='fa " + tipoCadeado + "' data-idUsuario='" + data['DT_RowId'] + "' data-nome='" + data['NomeUsuario'] + "' data-ativo='" + data['Ativo'] + "'/></i></a>"); 
                        $('td:eq(8)', row).html("<a title='Excluir Usuário' href='#'><i class='glyphicon glyphicon-trash' data-idUsuario='" +data['DT_RowId'] + "' data-nome='" + data['NomeUsuario'] + "'/></i></a>");                     
                    }       
          },
    } );    
    
  • APoncianoAPonciano Posts: 4Questions: 1Answers: 0

    Hi, just figured it out, the data is being sent correctly, but since I`m using SLIM framework is is not being passed the way the framework is expecting.. I need to send the data as a JSON structure.. any hints?

  • APoncianoAPonciano Posts: 4Questions: 1Answers: 0

    Just figured out a workaround.. changed the line 2336 in datatable.js to ( "data": JSON.stringify(data) )

This discussion has been closed.