简体   繁体   English

如何在 DataTable 子行中使用 jQuery 返回 div

[英]How to return a div using jQuery in a DataTable child row

I have a problem when returning a div using jQuery.使用 jQuery 返回 div 时遇到问题。 The attached code below works only until the first display of childRow content, unfortunately not later.下面的附加代码仅在第一次显示 childRow 内容之前有效,不幸的是不能稍后。 This is probably due to returning an item with the same ID, does anyone have an idea how else to return this div?这可能是由于返回了具有相同 ID 的项目,有人知道如何返回这个 div 吗?

Script脚本

function format () {
    return $('#myDiv');
}

(document).ready(function() {
    var table = $('#myTable').DataTable( {
       // table settings
    } );

    $('#myTable tbody').on('click', 'td', function () {
        var tr = $(this).closest('tr');
        var row = table.row( tr );

        if ( row.child.isShown() ) {
            row.child.hide();
        }
        else {
            row.child( format() ).show();
        }
    } );
} );

myDiv我的Div

div(id="myDiv" class="container"){
//some images
//some java bean references
}

I was able to solve the problem by changing the Javascript library files, according to the example根据示例,我能够通过更改 Javascript 库文件来解决问题

如何返回<div>在数据表中</div><div id="text_translate"><p>我在 laravel 中创建了项目,上面有数据表。 我想在我的列中返回一个 div 值作为进度条。 但是,我的表格中只显示文本,而不是进度条。 这是我的 controller</p><pre> public function index(Request $request) { if ($request-&gt;ajax()) { $data = Post::where('user_id', Auth::id())-&gt;latest()-&gt;get(); return Datatables::of($data) -&gt;addIndexColumn() -&gt;addColumn('progress', function ($row) { $pro = $row-&gt;progress; if ($pro == 0) { $bar = '&lt;div class="progress"&gt; &lt;div class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"&gt;0%&lt;/div&gt;&lt;/div&gt;'; return $bar; } else if (){}... }) -&gt;rawColumns(['action']) -&gt;make(true); } return view('Home'); }</pre><p> 这是我的看法</p><pre> $(function() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); var table = $('.data-table').DataTable({ processing: true, serverSide: true, ajax: "{{ route('home.index') }}", columns: [{ data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false, }, { data: 'title', name: 'title', orderable: false, }, { data: 'content', name: 'content', orderable: false, visible: false, }, { data: 'progress', name: 'progress' }, { data: 'status', name: 'status' }, { data: 'action', name: 'action', orderable: false, searchable: false }, ] });</pre><p> 我想在每个进度列中添加<a href="https://getbootstrap.com/docs/4.0/components/progress/" rel="nofollow noreferrer">引导进度</a>,可以吗? 还是我的代码有问题? 提前致谢</p></div> - How to return <div> in DataTable

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用jquery使子div在一行上相等 - Make child div equal on a row using jquery 如何返回<div>在数据表中</div><div id="text_translate"><p>我在 laravel 中创建了项目,上面有数据表。 我想在我的列中返回一个 div 值作为进度条。 但是,我的表格中只显示文本,而不是进度条。 这是我的 controller</p><pre> public function index(Request $request) { if ($request-&gt;ajax()) { $data = Post::where('user_id', Auth::id())-&gt;latest()-&gt;get(); return Datatables::of($data) -&gt;addIndexColumn() -&gt;addColumn('progress', function ($row) { $pro = $row-&gt;progress; if ($pro == 0) { $bar = '&lt;div class="progress"&gt; &lt;div class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"&gt;0%&lt;/div&gt;&lt;/div&gt;'; return $bar; } else if (){}... }) -&gt;rawColumns(['action']) -&gt;make(true); } return view('Home'); }</pre><p> 这是我的看法</p><pre> $(function() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); var table = $('.data-table').DataTable({ processing: true, serverSide: true, ajax: "{{ route('home.index') }}", columns: [{ data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false, }, { data: 'title', name: 'title', orderable: false, }, { data: 'content', name: 'content', orderable: false, visible: false, }, { data: 'progress', name: 'progress' }, { data: 'status', name: 'status' }, { data: 'action', name: 'action', orderable: false, searchable: false }, ] });</pre><p> 我想在每个进度列中添加<a href="https://getbootstrap.com/docs/4.0/components/progress/" rel="nofollow noreferrer">引导进度</a>,可以吗? 还是我的代码有问题? 提前致谢</p></div> - How to return <div> in DataTable 如何在 jquery 数据表中创建子行以显示订单详情? - How to create child row to display the order details in jquery datatable? jQuery DataTable:子行控制错误 - Jquery DataTable :child row control error 使用数据表中的两个Ajax调用基于父行上的ID获取子行中的数据-jQuery - Get data in child row based on id on parent row, using two ajax calls in datatable - jQuery 如何使用jQuery定位兄弟姐妹的孩子 - How to target a child of a sibling div using jquery 如何使用jQuery显示正确的子代“ div”? - How to show the correct child “div” using jQuery? 使用Ajax将HTML加载到Datatable子行中 - Load html into Datatable child row using ajax 如何在Jquery数据表中选择一行 - How to select a row in Jquery datatable 如何通过单击按钮使用jQuery将子div附加到父div - How to append child div into a parent div using jquery on the click of a button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM