Datatables Laravel 使用 yajrabox 在 ajax 调用中进行循环。

huangapple go评论68阅读模式
英文:

Datatables Laravel loop in ajax call using yajrabox

问题

// 如何使用 for 循环来添加直到第31天的列?或者我需要手动添加?另外,关于 `tgl: tgl`,我传递的 tgl 数据是作为数组,这样可以吗?
英文:
 function setDataTableTgl(tgl = null, tglA = null, tglB = null, departemenId = null, group = true){
      setColumn(group);
      var tgl = {};
for (var i=1; i < 32; i++) {             
        tgl[i] = i; 
      };
      $('.tableCustom3').DataTable().destroy();
      $('.tableCustom3').DataTable({
        processing: true,
        serverSide: true,
        bPaginate: false,
        ajax: {
          url: "{{ route('scoreboard.index') }}",
          type: "GET",
          data: {
            tglA: tglA,
            tglB: tglB,
            departemenId: departemenId,
            group: group,
            tgl: tgl
          }
        },
        columns: [
          { data: 'DT_RowIndex', name: 'DT_RowIndex' },
          { data: 'cabang', name: 'cabang' },
          { data: 'score', name: 'score' },
          { data: 'action', name: 'action' },
          { data: 'Day 1', name: 'Day 1' },
          { data: 'Day 2', name: 'Day 2' },
          { data: 'Day 3', name: 'Day 3' },
          { data: 'Day 4', name: 'Day 4' },
//i want this data to continue until Day 31
        ]
      });
    }

how to add the column that long with for ? or do i just have to manual it and also like to ask about the tgl: tgl i pass the tgl data as array would it work ?

答案1

得分: 0

使用**JSON.stringify(array)**函数传递tgl数据。

ajax: {
    url: "{{ route('scoreboard.index') }}",
    type: "GET",
    data: {
        tglA: tglA,
        tglB: tglB,
        departemenId: departemenId,
        group: group,
        tgl: JSON.stringify(tgl)
    }
}
英文:
  • pass tgl data using JSON.stringify(array) function.

    ajax: {
               url: "{{ route('scoreboard.index') }}",
               type: "GET",
               data: {
                 tglA: tglA,
                 tglB: tglB,
                 departemenId: departemenId,
                 group: group,
                 tgl: JSON.stringify(tgl)
               }
             },
    

huangapple
  • 本文由 发表于 2023年2月6日 09:46:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356704.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定