【问题标题】:How to solve this error (Uncaught TypeError: Cannot read property 'aDataSort' of undefined)?如何解决这个错误(Uncaught TypeError: Cannot read property 'aDataSort' of undefined)?
【发布时间】:2019-01-21 22:17:57
【问题描述】:

我该如何解决这个问题,这是我的代码:

<html>
    <head>
    <script>       
    $(function() {
        $('#pemohon-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: 'http://localhost:8000/pemohon/get_datatable'
        });
    });
    </script>
    </head>

    <body>
    <table id="pemohon-table" class="table">
        <thead>
            <tr>No</tr>
            <tr>Nomor Permohonan</tr>
            <tr>Tanggal Permohonan</tr>
            <tr>Nama</tr>
            <tr>Tanggal Lahir</tr>
            <tr>Status</tr>
        </thead>
    </table>
    </body>

我得到了这个错误:

未捕获的类型错误:无法读取未定义的属性“aDataSort”

我不知道到底是什么问题,请帮助我。谢谢。

【问题讨论】:

  • 您的服务器端脚本可能已返回错误。检查您的日志
  • 你能发布整个代码吗?

标签: ajax laravel datatable datatables


【解决方案1】:

如果你使用数据表,也许你可以这样设置:

在控制器中创建 getData 函数

public function getData(Request $request){
    $pemohon = YourModel::select('your_coloum_in_database.*');
    return Datatables::of($pemohon)
                    ->make(true);
}

在您看来,您可以这样调用:

<table class="table table-bordered table-hover table-striped w100" cellspacing="0" id="datatable"></table>

    <script>


$('#datatable').dataTable({
                        processing: true,
                        serverSide: true,
                        ajax: {
                            method: 'POST',
                            url : '{{ route('your_route') }}',
                            headers: {
                                'X-CSRF-TOKEN': '{{ csrf_token() }}'
                            }
                        },
                        columns : [
                            {title: 'No', data: 'no, name: 'no', defaultContent: '-', class: 'text-center'},
                            {title: 'Nomor Permohonan', data: 'nomor_permohonan', name: 'nomor_permohonan', defaultContent: '-', class: 'text-center'},
                            {title: 'Tanggal Permohonan', data: 'tanggal_permohonan', name: 'tanggal_permohonan', defaultContent: '-', class: 'text-center'},
                            {title: 'Nama', data: 'nama', name: 'nama', defaultContent: '-', class: 'text-center'},
                            {title: 'Tanggal Lahir', data: 'tanggal_lahir', name: 'tanggal_lahir', defaultContent: '-', class: 'text-center'},{title: 'Status', data: 'status', name: 'status', defaultContent: '-', class: 'text-center'},
    </script>

【讨论】:

    猜你喜欢
    • 2017-04-24
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2020-10-13
    • 2020-10-29
    • 2019-02-12
    • 2018-01-24
    相关资源
    最近更新 更多