2012-05-09 80 views
2

我想更新一個自定義參數,我在jQuery數據表中創建的.datatable()函數以外的函數。自定義jquery數據表參數

var oTable = $('#reqAllQueriesTable') 
     .dataTable(
       { 
       "bProcessing": true, 
       "bServerSide": true, 
       "sAjaxSource": "query/getQuery", 
       "bFilter" : true, 
       "bJQueryUI" : true, 
       "sSearch": "Search", 
       "sDom": '<"H"<"projectTeamTools">lrft>', 
       "fnServerData": function (sSource, aoData, fnCallback) { 
          aoData.push({ "name": "myParam", "value": "myValue" }); 
           $.ajax({ 
            "dataType": 'json', 
            "url": sSource, 
            "data": aoData, 
            "success": fnCallback 
            }); 
         } 
       }); 

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

function onTeamSelect(teamId){ 
    alert(teamId +" Selected"); 
    //oTable.fnSettings().aoServerParams.push({ name: "aoTeamId", value: teamId }); 
       //I want to update the parameter `myParam` here. 
       //Or create a new parameter 'aoTeamId', whichever is possible. 
} 

這是可能的:

我通過創建自定義參數。請幫忙!

謝謝, Sunmit。

回答

3

不需要覆蓋fnServerData參數。爲了您的目的,用以下行覆蓋fnServerParams參數:

"fnServerParams": function (aoData) { 
    aoData.push({ "name": "teamId", "value": $("#projectTeams").val() }); 
}