数据表自动获取Bubble Editor(Laravel + Blades)的thead值

时间:2017-09-25 18:56:41

标签: php jquery datatables laravel-5.4

我使用laravel 5.4和Blades + DataTables,我想使用Bubble Editor(Datatables),例如:https://editor.datatables.net/examples/bubble-editing/simple

但是我从Blades得到了我的名字,而不是来自json。我怎么能得到这样的泡泡编辑器?

    <table id="main_grid" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
        <thead id='main_grid_thead'>
            <tr>
                @foreach($tablefields as $field)
                    <th>{{ $field['detail_field']['grid']['label'] }}</th>
                @endforeach
            </tr>
        </thead>
        <tbody>
            <!-- TABLE BODY HERE-->
        </tbody>
    </table>

我得到了一个带有数据表的JS函数

var editor = new  $.fn.dataTable.Editor( {
        ajax: "../php/staff.php",
        table: '#'+id_grid
      });

  $('#'+id_grid).dataTable({
          sInfo: '',
          "sDom": '<"html5buttons"B><"top"fZ>rt<"bottom"lpi><"clear"> ',
          "oListNav": {
                    //SOME CODE
            },
          pageLength: 10,
          responsive: true,

      });


  $('#' + id_grid).on( 'click', 'tbody td:not(:first-child)', function (e) {
          editor.bubble( $('#' + id_grid + ' tbody tr:first-child td:first-child') );
      } );

1 个答案:

答案 0 :(得分:1)

我找到了解决方案

$('#' + id_grid ).on( 'click', 'tbody td i', function (e) {
 $(this).parent().children('i').attr('style','display:none; float: right;')
  editor.bubble( $(this).parent() )