jquery datatable调用.clear().draw()方法后不能清空表格数据

2022-03-28 17:56:11 浏览数 (1)

使用jquery datatable时如果采用了下面配置

代码语言:javascript复制
$('#xx').DataTable({
        "serverSide": true,  --在服务端处理数据
        "processing": true,
        "bAutoWidth": false,
        "autoWidth": false,
 

那么这种情况下不能通过.clear().draw()方法来清除datatable,因为draw方法会引起table reload方法调用!

部分相关代码:

代码语言:javascript复制
function _fnDraw( oSettings )
 {
 /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
 var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
 if ( $.inArray( false, aPreDraw ) !== -1 )
 {
 _fnProcessingDisplay( oSettings, false );
 return;
 }
 
 var i, iLen, n;
 var anRows = [];
 var iRowCount = 0;
 var asStripeClasses = oSettings.asStripeClasses;
 var iStripes = asStripeClasses.length;
 var iOpenRows = oSettings.aoOpenRows.length;
 var oLang = oSettings.oLanguage;
 var iInitDisplayStart = oSettings.iInitDisplayStart;
 var bServerSide = _fnDataSource( oSettings ) == 'ssp';
 var aiDisplay = oSettings.aiDisplay;
 
 oSettings.bDrawing = true;
 
 /* Check and see if we have an initial draw position from state saving */
 if ( iInitDisplayStart !== undefined && iInitDisplayStart !== -1 )
 {
 oSettings._iDisplayStart = bServerSide ?
 iInitDisplayStart :
 iInitDisplayStart >= oSettings.fnRecordsDisplay() ?
 0 :
 iInitDisplayStart;
 
 oSettings.iInitDisplayStart = -1;
 }
 
 var iDisplayStart = oSettings._iDisplayStart;
 var iDisplayEnd = oSettings.fnDisplayEnd();
 
 /* Server-side processing draw intercept */
 if ( oSettings.bDeferLoading )
 {
 oSettings.bDeferLoading = false;
 oSettings.iDraw  ;
 _fnProcessingDisplay( oSettings, false );
 }
 else if ( !bServerSide )
 {
 oSettings.iDraw  ;
 }
 else if ( !oSettings.bDestroying && !_fnAjaxUpdate( oSettings ) )
 {
 return;
 }
 

0 人点赞