dimanche 16 février 2020

cant display html element using yajra data table

good day, iam new in laravel i traying to use yajra data tabel i have easy question when i want to show my data tabel i get this error "DataTables warning: table id=all_data - Ajax error. For more information about this error, please see http://datatables.net/tn/7" my controller is

public function indexUsingYajra() {

    $dataView['allCategories']=Category::where('deleted',1)->get();
    return Datatables::of($dataView['allCategories'])
        ->setRowId('')

        //image coulmn
        ->addColumn('image', function(Category $category) {
            return '<img src="/upload/'.$category->image.'"  data-id="'.$category->id.'" data-toggle="modal" data-target="#update-img"  alt="" title="Edit Image" class="img-rounded img-responsive center-block img-edit imagenumber'.$category->id.'" />';
        })
        // totalproduct
        ->addColumn('Total Product', function(Category $category) {
            return  $category->getCategoryReportData->total_orders;
        })
        //status column
        ->addColumn('status', function(Category $category) {
            if ($category->status==1)
            {
                return '<span data-id="'.$category->id.'" title="update Status" data-target="on" class="status on ">on</span>';
            }else{
                return '<span data-id="'.$category->id.'" title="update Status"  data-target="off" class="status off">off</span>';
            }

        })
        // active column
        ->addColumn('action', function(Category $category) {
            return'<ul class="actions">
                    <li><a href="'. route('category.edit', $category->id) .'">'.$category->name.'</a></li>
                </ul>';
        })

        //render html element in page
        ->rawColumns(['image', 'status','action'])
        ->make(true);
}

my js code $('#all_data').DataTable({

            "responsive": true,
            "processing": true,
            "serverSide": true,
            "ajax": "{!!route('category.indexUsingYajra')!!}",
            "columns": [
                {data: 'id',       name: 'id'},
                {data: 'name',       name: 'name'},
                {data: 'image',       name: 'image'},
                {data: 'Total Product',       name: 'Total Product'},
                {data: 'status',       name: 'status'},
                {data: 'action',       name: 'action'},



            ]
        });

my html code

 <table id="all_data" class="table-striped table-bordered dt-responsive nowrap tableData  table_for_data" cellspacing="0" width="100%">
                                <thead>
                                    <tr>
                                        <th>Id</th>
                                        <th>Name</th>
                                        <th>Image</th>
                                        <th>Total Product</th>
                                        <th>status</th>
                                        <th>action</th>
                                    </tr>
                                </thead>

                            </table>

my this problem happen if i want to view links in column (action) if i remove it data table work correctly and if i remove any column that contain any html element like (image) or (status) action column work correctly . how can i solve it thnaks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire