2012-10-01 46 views
0

我想添加nowrap爲我的jquery數據表而沒有成功。從json動態jquery數據表的Nowrap

這樣的事情(不工作)

$.ajax({ 
    "url": 'invokeHawkAgent.gsp', 
    "success": function (json) { 
     json.bDestroy = true; 
     $('#tabs-1-contents').dataTable({'data':json, 
      "fnRowCallback": function(nRow, aData, iDisplayIndex) { 
       $('td', nRow).attr('nowrap','nowrap'); 
       return nRow; 
      } 
     }); 
    }, 
    "dataType": "json" 
}); 

工作(但沒有NOWRAP)

$.ajax({ 
    "url": 'invokeHawkAgent.gsp', 
    "success": function (json) { 
     json.bDestroy = true; 
     $('#tabs-1-contents').dataTable(json); 
    }, 
    "dataType": "json" 
}); 

任何想法如何NOWRAP添加到這個?

謝謝!

+1

你爲什麼不只是從CSS設置呢? – Nelson

+0

其實我想用jquery在dataTable函數的表中添加更多的特性。設置nowrap只是實現這一目標的第一步。 – user955732

+0

Duplicate:http://stackoverflow.com/questions/2270244/datatables-jquery-plugin-nowrap-for-ajax-table? @ user955732 http://datatables.net/forums/discussion/1365/nowrap-for-ajax-table/p1討論了這個問題,並提供了兩種解決方法,試一下,如果有效,你可以發佈你自己的答案。 –

回答

1

任何有興趣,這是我解決了這個問題:

JSON

{ 
    "aaData":[ 
    { 
     "0": "2010-07-27 10:43:08", 
     "1" : "...", 
     "2" : "...", 
     "3" : "...", 
     "4" : "...", 
     "5" : "...", 
     "6" : "...", 
     "7" : "...", 
     "DT_RowId": "row", 
     "DT_RowClass": "gradeC" 
    }, 
    { 
     "0": "2010-07-27 10:43:08", 
     "1" : "...", 
     "2" : "...", 
     "3" : "...", 
     "4" : "...", 
     "5" : "...", 
     "6" : "...", 
     "7" : "...", 
     "DT_RowId": "row", 
     "DT_RowClass": "gradeC" 
    } 
    ] , 
    "aaSorting": [ 
     [ 1, "desc" ] 
    ], 
    "aoColumns": [ 
     { "sTitle": "Title1" }, 
     { "sTitle": "Title2" }, 
     { "sTitle": "Title3" }, 
     { "sTitle": "Title4" }, 
     { "sTitle": "Title5" }, 
     { "sTitle": "Title6" }, 
     { "sTitle": "Title7" }, 
     { "sTitle": "Title8" } 
    ] 
} 

的jQuery:

$.ajax({ 
    "url": 'invokeHawkAgent.gsp', 
    "success": function (json) { 
     json.bDestroy = true; 
     $('#tabs-1-contents').dataTable({ 
      "aaData": json.aaData, 
      "aoColumns": json.aoColumns, 
      "sScrollX": "100%", 
      "sScrollXInner": "110%", 
      "bScrollCollapse": true, 
      "sScrollY": "500px", 
      "bPaginate": true, 
      "fnRowCallback": function(nRow, aData, iDisplayIndex) { 
       $('td', nRow).attr('nowrap','nowrap'); 
       return nRow; 
       } 
      }); 
     }, 
    "dataType": "json" 
});