簡體   English   中英

jQuery數據表Ajax分頁

[英]Jquery datatable Ajax pagination

嗨,有這個JS腳本:

<script type="text/javascript" src="/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script>
    $(document).ready(function() {
        $('#usersTable').DataTable({
            "sPaginationType": "full_numbers",
            "bProcessing": true,
            "bServerSide": true,
            "bDeferRender": true,
            "sAjaxSource": "{{ path('prospection_prospects_ajax') }}",
            "bJQueryUI": true,
            "sPaginationType": "full_numbers"
        });
        $.fn.dataTableExt.sErrMode = 'throw';
    });
</script>

此HTML代碼:

<table id="usersTable" class="table">
    <thead>
    <tr>
        <th>Societe</th>
        <th style="width:150px;">Telephone</th>
        <th>Description</th>
        <th>Actions</th>
    </tr>
    </thead>
    <tbody>
    {% for prospect in prospects %}
        <tr>
            <td>{{ prospect.societe}}</td>
            <td>{{ prospect.telephone }}</td>
            <td>{{ prospect.description }}</td>
            <td>
                <a href="{{ path("prospection_prospect_details",{userId:user.id}) }}">Details</a><br />
                <a href="{{ path("prospection_prospect_details",{userId:user.id}) }}">Supprimer</a><br />
                <select>
                    <option value="prospect">Prospect</option>
                    <option value="Contacter">Contacté</option>
                </select>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>

然后返回此JSON(我返回100條記錄乘以100條記錄):

{
"recordsTotal": 5055,
"recordsFiltered": 5055,
"draw": 1,
"records": [{
    "name": "Alerys",
    "telephone": "01 42 96 08 37",
    "description": "Prestations : cabinet de recrutement informatique, Evaluation, « Assessment Center », Bilan de carrière, Conseils en mobilité professionnelle et en organisation, Audit, Délégation de ressources, chasseur de tête, test psychotechnique, reconversion profess",
    "link": "<select><option value='prospect'>Prospect</option><option value='Contacter'>Contacté</option></select>"
}, {
    "name": "EuroWin Consulting Group",
    "telephone": "01 42 27 73 00",
    "description": "cabinet de recrutement informatique",
    "link": "<select><option value='prospect'>Prospect</option><option value='Contacter'>Contacté</option></select>"
} ...
]

然后Datable向我拋出此錯誤:未捕獲的錯誤:DataTables警告:table id = usersTable-無效的JSON響應。

我無法進行作品分頁。

有人可以幫助我嗎?

最好的祝福

您確定records是密鑰的名稱。

在Datatable的官方站點上,密鑰的名稱是data

https://datatables.net/examples/data_sources/server_side.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM