Help aodata.push with the new datatable 1.10

Help aodata.push with the new datatable 1.10

lucianocorteslucianocortes Posts: 7Questions: 1Answers: 0

Hi, Please I need someone explain me how it works the new version of datatable with aodata.push. I tried everything but nothing works... please some help

'sAjaxSource': "Principal.aspx/ObtenerRegistros",
"fnServerData": function (sSource, aoData, fnCallback) { 
        aoData.push({ "name": "stRefrescarBoset", "value": $("#stRefrescarBoset").val() });
        aoData.push({ "name": "LISTA_CAMPOS_BUSQUEDA", "value": $("#LISTA_CAMPOS_BUSQUEDA").val() });
        aoData.push({ "name": "LISTA_VALORES_BUSQUEDA", "value": $("#LISTA_VALORES_BUSQUEDA").val() });
        aoData.push({ "name": "LISTA_OPERADORES", "value": $("#LISTA_OPERADORES").val() });
        aoData.push({ "name": "LISTA_TIPO_DATOS", "value": $("#LISTA_TIPO_DATOS").val() });
        aoData.push({ "name": "LISTA_CAMPOS_SELECT", "value": $("#LISTA_CAMPOS_SELECT").val() });
        aoData.push({ "name": "LISTA_CAMPOS_FORMATOS", "value": $("#LISTA_CAMPOS_FORMATOS").val() });
        aoData.push({ "name": "LISTA_CAMPOS_LARGOS", "value": $("#LISTA_CAMPOS_LARGOS").val() });
        aoData.push({ "name": "LISTA_CAMPOS_ALINEACION", "value": $("#LISTA_CAMPOS_ALINEACION").val() });
        aoData.push({ "name": "iLinkColum", "value": $("#iLinkColum").val() });
        aoData.push({ "name": "bOnlySelectedIds", "value": $("#chkOnlySelectedIds").is(':checked') });
        aoData.push({ "name": "stPreFilter", "value": $("#stPreFilter").val() });
        $.ajax({
            "dataType": 'json',
            "contentType": "application/json; charset=utf-8",
            "type": "POST",
            "url": sSource,
            "data": aoData,
            "async": true,
            "success": function (responseJson) {
                var response = JSON.parse(responseJson["d"]);
                }
            });
}

Any advice... some i have to look... please... some exaple!
Thanks

This question has accepted answers - jump to:

Answers

  • lucianocorteslucianocortes Posts: 7Questions: 1Answers: 0

    I made this but it doesn't work :(

    data: function (d) {
                            d.stRefrescarBoset = $("#stRefrescarBoset").val(),
                                d.LISTA_CAMPOS_BUSQUEDA = $("#LISTA_CAMPOS_BUSQUEDA").val(),
                                d.LISTA_VALORES_BUSQUEDA = $("#LISTA_VALORES_BUSQUEDA").val(),
                                d.LISTA_OPERADORES = $("#LISTA_OPERADORES").val(),
                                d.LISTA_TIPO_DATOS = $("#LISTA_TIPO_DATOS").val(),
                                d.LISTA_CAMPOS_SELECT = $("#LISTA_CAMPOS_SELECT").val(),
                                d.LISTA_CAMPOS_LARGOS = $("#LISTA_CAMPOS_LARGOS").val(),
                                d.LISTA_CAMPOS_ALINEACION = $("#LISTA_CAMPOS_ALINEACION").val(),
                                d.iLinkColum = $("#iLinkColum").val(),
                                d.bOnlySelectedIds = $("#chkOnlySelectedIds").is(':checked'),
                                d.stPreFilter = $("#stPreFilter").val()
                            return JSON.stringify({ gridParams: d });
                        },
    
  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    The fnServerData method is legacy. If you want to add data to be sent to the server use ajax.data - example here.

    Allan

  • lucianocorteslucianocortes Posts: 7Questions: 1Answers: 0

    Hi allan!

    I use the exaple but it doesn't work... i'm usin a webmethod with this code:

    data: function (d) {
                            d.stRefrescarBoset = $("#stRefrescarBoset").val(),
                                d.LISTA_CAMPOS_BUSQUEDA = $("#LISTA_CAMPOS_BUSQUEDA").val(),
                                d.LISTA_VALORES_BUSQUEDA = $("#LISTA_VALORES_BUSQUEDA").val(),
                                d.LISTA_OPERADORES = $("#LISTA_OPERADORES").val(),
                                d.LISTA_TIPO_DATOS = $("#LISTA_TIPO_DATOS").val(),
                                d.LISTA_CAMPOS_SELECT = $("#LISTA_CAMPOS_SELECT").val(),
                                d.LISTA_CAMPOS_LARGOS = $("#LISTA_CAMPOS_LARGOS").val(),
                                d.LISTA_CAMPOS_ALINEACION = $("#LISTA_CAMPOS_ALINEACION").val(),
                                d.iLinkColum = $("#iLinkColum").val(),
                                d.bOnlySelectedIds = $("#chkOnlySelectedIds").is(':checked'),
                                d.stPreFilter = $("#stPreFilter").val()
                            return JSON.stringify({ gridParams: d });
                        },
    

    The error said that I need a Constructor... I don't understand

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Is your data function inside the ajax object like in the example?

    Are you saying that the page I linked to doesn't work for you? It does for me.

    Allan

  • lucianocorteslucianocortes Posts: 7Questions: 1Answers: 0

    The Page it works... the example it doesn't.
    Thanks anyway

  • jaclerigojaclerigo Posts: 6Questions: 1Answers: 2
    edited April 2018 Answer ✓

    Hello,

    try something like:

    "serverSide" : true, 
    "ajax": {
        "url" : $url,
            "data": function(d) {
            return $.extend({}, d, {
                "field1" : $("#field1").val(),
                "field2" : $("#field2").val(),
                "field3" : $("select#field3 option:selected").val()
                });
            }
        },
    
  • lucianocorteslucianocortes Posts: 7Questions: 1Answers: 0

    Thanks jaclerigo! it works!

  • jaclerigojaclerigo Posts: 6Questions: 1Answers: 2
    Answer ✓

    @lucianocortes great. Glad to have helped.

This discussion has been closed.