JQuery Datatable - 放置自定义加载GIF而不是默认的“处理”文本

时间:2021-05-02 14:25:45

I'm using the current version of JQuery Datatable. I have implemented server-side processing. Is there any way to place our own Loading GIF instead of the dafault text "Processing"?

我正在使用当前版本的JQuery Datatable。我已经实现了服务器端处理。有没有办法放置我们自己的加载GIF而不是dafault文本“处理”?

Here's my HTML code :

这是我的HTML代码:

<table id="table" class="table table-striped table-bordered table-hover display nowrap" cellspacing="0" width="100%">
  <thead>
    <tr bgcolor="#76b900">
      <th> Request #</th>
      <th>Description</th>
      <th>Created By</th>
    </tr>
  </thead>
</table>

Here's my JS code :

这是我的JS代码:

$('#table').DataTable({
    "dom": '<"top"lB>rt<"bottom"ip>', // DataTable element position


    "lengthMenu": [
      [10, 25, 50, 100, 500],
      [10, 25, 50, 100, 500]
    ], // page length options
    "pageLength": 25, // default page length
    "pagingType": "full_numbers", // pagination related buttons

    "ordering": true,
    "order": [
      [0, "desc"]
    ],

    "scrollX": true, // enables horizontal scrolling      
    "filter": true,
    "responsive": true,
    "serverSide": true,
    "info": true, // control table information display field
    "processing": true,
    "stateSave": true, //restore table state on page reload,

    "ajax": {
      "url": Helper.baseUrl() + "Search/LoadData",
      "type": "POST",
      "datatype": "json",
      "data": function(d) {
        d.searchParams = searchFilters();
      },
    },

    "columns": //Binds values fetched from the database to their respective columns
      [{
      "data": "RequestNo",


    }, {
      "data": "Description"
    }, {
      "data": "CreatedBy"
    }],
  });

UPDATE

UPDATE

This is my updated JS code for Processing :

这是我更新的JS代码:

"language": {
            "infoFiltered":"",
            "processing": "<img src='~/Content/images/loadingNew.gif' />"
        },

This didn't work. Am I including the path in wrong technique?

这没用。我是否包括错误技术的路径?

2 个解决方案

#1


3  

Take a look at this DEMO I have made.

看看我制作的这个DEMO。

  var table = $('#changeLogTable').DataTable({
        "bLengthChange": false,
        "bPaginate": true,
        "bInfo": false,
        "autoWidth": false, 
        "order": [[0, "desc"]],
        "processing": true,
        "serverSide": true,
        "sAjaxSource": "data.js",
         oLanguage: {sProcessing: "<div id='loader'></div>"}
    }); 

})

})

#2


1  

SOLVED :-

解决了 :-

Initially I had included path in a wrong manner.
Using @Offir Pe'er answer I got it working (with the only modification currently in my code is that I've used current version i.e. 1.10 syntax).

最初我以错误的方式包含了路径。使用@Offir Pe'er回答我得到了它的工作(目前在我的代码中唯一的修改是我使用了当前版本,即1.10语法)。

This is how my code looks now :-

这就是我的代码现在的样子: -

"language": 
{          
"processing": "<img style='width:50px; height:50px;' src='Content/images/loadingNew.gif' />",
}

So I just had to remove the '~' from my previously updated code.

所以我只需从我之前更新的代码中删除'〜'。

Here's my directory structure :

这是我的目录结构:

-Root Folder

-根文件夹

  • Content

    内容

    • Images

      图片

      • loadingNew.gif
      • loadingNew.gif
  • Scripts

    脚本

    • MyJSFile.js
    • MyJSFile.js

#1


3  

Take a look at this DEMO I have made.

看看我制作的这个DEMO。

  var table = $('#changeLogTable').DataTable({
        "bLengthChange": false,
        "bPaginate": true,
        "bInfo": false,
        "autoWidth": false, 
        "order": [[0, "desc"]],
        "processing": true,
        "serverSide": true,
        "sAjaxSource": "data.js",
         oLanguage: {sProcessing: "<div id='loader'></div>"}
    }); 

})

})

#2


1  

SOLVED :-

解决了 :-

Initially I had included path in a wrong manner.
Using @Offir Pe'er answer I got it working (with the only modification currently in my code is that I've used current version i.e. 1.10 syntax).

最初我以错误的方式包含了路径。使用@Offir Pe'er回答我得到了它的工作(目前在我的代码中唯一的修改是我使用了当前版本,即1.10语法)。

This is how my code looks now :-

这就是我的代码现在的样子: -

"language": 
{          
"processing": "<img style='width:50px; height:50px;' src='Content/images/loadingNew.gif' />",
}

So I just had to remove the '~' from my previously updated code.

所以我只需从我之前更新的代码中删除'〜'。

Here's my directory structure :

这是我的目录结构:

-Root Folder

-根文件夹

  • Content

    内容

    • Images

      图片

      • loadingNew.gif
      • loadingNew.gif
  • Scripts

    脚本

    • MyJSFile.js
    • MyJSFile.js