Correctly Suppressing Warnings in DataTables?

前端 未结 6 2219
小蘑菇
小蘑菇 2020-12-24 12:13

I\'m trying to correctly suppress warnings (alerts) in DataTables. The standard behavior of DataTables is to throw a javascript alert when an error occurs; however, this is

6条回答
  •  长发绾君心
    2020-12-24 12:40

    Here's a solution proposed here that's slightly modified and works in v1.10.2 without having to change any vendor files:

    $.fn.dataTableExt.sErrMode = "console";
    
    $.fn.dataTableExt.oApi._fnLog = function (oSettings, iLevel, sMesg, tn) {
      var sAlert = (oSettings === null)
        ? "DataTables warning: "+sMesg
        : "DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg
      ;
    
      if (tn) {
        sAlert += ". For more information about this error, please see "+
                  "http://datatables.net/tn/"+tn
        ;
      }
    
      if (iLevel === 0) {
        if ($.fn.dataTableExt.sErrMode == "alert") {
          alert(sAlert);
        } else if ($.fn.dataTableExt.sErrMode == "thow") {
          throw sAlert;
        } else  if ($.fn.dataTableExt.sErrMode == "console") {
          console.log(sAlert);
        } else  if ($.fn.dataTableExt.sErrMode == "mute") {}
    
        return;
      } else if (console !== undefined && console.log) {
        console.log(sAlert);
      }
    }
    

提交回复
热议问题