1.  
  2. //配置DataTables默认参数
  3. $.extend(true, $.fn.dataTable.defaults, {
  4. "language": {
  5. "url": "/assets/Chinese.txt"
  6. },
  7. "dom": "<'row'<'col-md-6'l<'#toolbar'>><'col-md-6'f>r>" +
  8. "t" +
  9. "<'row'<'col-md-5 sm-center'i><'col-md-7 text-right sm-center'p>>"
  10. });
  11.  
  12. //DataTables初始化
  13. $("#issueTable").DataTable({
  14. ajax: {
  15. url: "https://api.github.com/repos/ssy341/datatables-cn/issues",
  16. dataSrc: ""
  17. },
  18. //默认最后一列(最后更新时间)降序排列
  19. order: [[ 2, "desc" ]],
  20. columnDefs: [
  21. {
  22. targets: 2,
  23. data: "updated_at",
  24. title: "最后更新时间",
  25. render: function (data, type, row, meta) {
  26. return new Date(Date.parse(data)).Format("yyyy-MM-dd hh:mm:ss");
  27. }
  28. },
  29. {
  30. targets: 1,
  31. data: null,
  32. title: "发表人",
  33. render: function (data, type, row, meta) {
  34. return "<a href='" + row.user.html_url + "' target='_blank'>" + row.user.login + "</a>"
  35. }
  36. },
  37. {
  38. targets: 0,
  39. data: "title",
  40. title: "问题",
  41. render: function (data, type, row, meta) {
  42. var labels = "";
  43. if (row.labels.length) {
  44. labels += "【";
  45. for (var j = 0, labelslen = row.labels.length; j < labelslen; j++) {
  46. labels += "<span style='color:#" + row.labels[j].color + "' >" +
  47. row.labels[j].name + "</span>";
  48. if (j != labelslen - 1) {
  49. labels += ",";
  50. }
  51. }
  52. labels += "】";
  53. }
  54. var hot = "";
  55. if(labels.indexOf("置顶")>0){
  56. hot = "<span class='hot'></span>"
  57. }
  58. return "<a href='" + row.html_url + "' target='_blank'>" + row.title + "</a>" + labels +
  59. "<i class='icon Hui-iconfont'>&#xe622;</i>"+row.comments +hot;
  60. }
  61. }
  62. ],
  63. initComplete:function(){
  64. $("#toolbar").append("<a href='https://github.com/ssy341/datatables-cn/issues/new' " +
  65. "class='btn btn-primary btn-sm'>我也要提问</a>");
  66. }
  67. });
  68.  
  69. Date.prototype.Format = function (fmt) { //author: meizz
  70. var o = {
  71. "M+": this.getMonth() + 1,
  72. //月份
  73. "d+": this.getDate(),
  74. //日
  75. "h+": this.getHours(),
  76. //小时
  77. "m+": this.getMinutes(),
  78. //分
  79. "s+": this.getSeconds(),
  80. //秒
  81. "q+": Math.floor((this.getMonth() + 3) / 3),
  82. //季度
  83. "S": this.getMilliseconds() //毫秒
  84. };
  85. if (/(y+)/.test(fmt)) {
  86. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  87. }
  88. for (var k in o) {
  89. if (new RegExp("(" + k + ")").test(fmt)) {
  90. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  91. }
  92. }
  93. return fmt;
  94. };