Passing an extra parameter to a Java controller for jQuery datatables

I am trying to pass a custom parameter to a Java controller that acts as a data source in my jquery data table. The thing is, I want to do this (pass the parameter) in the change event for combobox on my jsp.

Here is my data initialization:

var oTable = $('#reqAllQueriesTable')
            .dataTable(
                    {
                        "sDom": '<"H"l<"projectTeamTools">frtip>',
                        "bProcessing": true,
                        "bServerSide": true,
                        "sAjaxSource": "query/getQuery",
                        "bPaginate" : true,
                        "bLengthChange": true,
                        "bScrollCollapse" : true,
                        "iDisplayLength" : 10,
                        "bFilter" : true,
                        "bJQueryUI" : true,
                        "sPaginationType" : "full_numbers",
                        "sSearch": "Search"
                    });

My summary, the values ​​of which should be passed to the controller and related functions:

    $("div.projectTeamTools").html('Organize by Project Teams: <select id="projectTeams"><option value="0">Project Team</option><option value="1">All</option><option value="2">Not Associated</option><c:forEach var="projectTeam" items="${userProjectTeams}"><option value="${projectTeam.projectId}">${projectTeam.projectName}</option></c:forEach></select>');  


    $("#projectTeams").change(function () {
        onTeamSelect($(this).val());
    }); 

    function onTeamSelect(teamId){
        alert(teamId +" Selected");
//This function to pass the parameter to the datatable is supposed to be here.
        oTable.fnDraw();
    }

The datatable then displays the new data it receives from ajax Source getQuery.

PS: I cannot use fnServerParams as I am using an older version of datatables. I tried using fnServerData, but that did not help. I think I'm wrong in how I use the ajax function in fnServerData.

"fnServerData": function ( sSource, aoData, fnCallback ) {
                            $("#projectTeams").change(function() { 
                                 aoData.push( { "name": "myParam", "value": $("#ComboBox option:selected").value() } );
                                    $.ajax( {
                                        "dataType": 'json', 
                                        "url": sSource, 
                                        "data": aoData, 
                                        "success": fnCallback
    });

, "Network XHR" , . , !

+3
1

. fnServerData :

"fnServerData": function ( sSource, aoData, fnCallback ) {
                    aoData.push( { "name" : "myTeamId", "value" : myTeamId  } );
                    $.getJSON( sSource, aoData, function (json) { 
                        fnCallback(json);
                    });
              }

onChange , :

    $("#projectTeams").change(function () {
        onTeamSelect($(this).val());
    }); 
    function onTeamSelect(teamId){
        myTeamId = teamId;
        oTable.fnDraw();
    }

myTeamId - . oTable.fnDraw() datatable teamId myTeamId, fnServerData. !

+2

All Articles