Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. if (bUsePassedData) {
  2. for (var i = 0, len = oInit.aaData.length; i < len; i++) {
  3. _fnAddData(oSettings, oInit.aaData[i]);
  4. }
  5. } else if (oSettings.bDeferLoading ||
  6. (oSettings.sAjaxSource === null && oSettings.ajax === null)) {
  7. _fnAddTr(oSettings, $(oSettings.nTBody).children('tr'));
  8. }
  9.  
  10. (oSettings.sAjaxSource === null && oSettings.ajax === null) // true
  11.  
  12. function beforeIf(){
  13. if (bUsePassedData) {
  14. procesData(oSettings,oInit.aaData.concat());
  15. } else if (oSettings.bDeferLoading ||
  16. (oSettings.sAjaxSource === null && oSettings.ajax === null)) {
  17. _fnAddTr(oSettings, $(oSettings.nTBody).children('tr'));
  18. }
  19. afterIF();
  20. }
  21. function processData(oSettings,arr){
  22. //process in chuncks of 50;
  23. // setTimeout takes a long time in IE
  24. // it'll noticibly slow donw your script when
  25. // only processing one item at the time
  26. var tmp=arr.splice(0,50);
  27. for (var i = 0, len = tmp.length; i < len; i++) {
  28. _fnAddData(oSettings, tmp[i]);
  29. }
  30. if(arr.length!==0){
  31. setTimeout(function(){
  32. processData(oSettings,arr);
  33. },0);
  34. return;
  35. }
  36. afterIf();
  37. }
  38. function afterIf(){
  39. //continue processing
  40. }
  41.  
  42. (function processData(oSettings, arr) {
  43.  
  44. var tmp = arr.splice(0, 50);
  45.  
  46. tickApp.$orders.dataTable().fnAddData(tmp);
  47.  
  48. if (arr.length !== 0) {
  49. setTimeout(function () {
  50. processData(oSettings, arr);
  51. }, 0);
  52. }
  53. }(oSettings, oInit.aaData.concat()));
  54.  
  55. tickApp.$orders = $('#orders');
  56.  
  57. var DEFAULT_CHUNK_SIZE = 200;
  58.  
  59. function feedDataToDataTableInChunks(data, oSettings) {
  60. var chunk = data.splice(0, DEFAULT_CHUNK_SIZE);
  61. oSettings.oInstance.fnAddData(chunk, false);
  62. if(data.length !== 0) {
  63. setTimeout(function () {
  64. feedDataToDataTableInChunks(data, oSettings);
  65. });
  66. } else {
  67. oSettings.oInstance.fnDraw();
  68. }
  69. }
  70.  
  71. var config = {fnServerData: function(){
  72. oSettings.jqXHR = $.getJSON(sSource, aoData)
  73. .done(function (result) {
  74. feedDataToDataTableInChunks(result || [], oSettings);
  75. });
  76. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement