ServerSide pagination MySQL, node js & ejs templating

ServerSide pagination MySQL, node js & ejs templating

ucinucin Posts: 13Questions: 4Answers: 0
edited May 2021 in DataTables

Hello all,

I've ben trying to get serverSide pagination to work over NodeJS backend and .ejs template frontend but haven't been able to so far.

Client side pagination is working great, except I have a lot of data so I'm currently limiting everything to 1000 rows per query.

Almost every example, guide I've come across so far has PHP in it and I have zero PHP knowledge and not really interested in learning it.

Can someone please point me to the right direction?

What I've tried so far is ;

this is the table body of my .ejs file

<tbody id="t_body" style="visibility: hidden;">


                                    <% for(var i=0; i< data.length; i++) { %>
                                        <tr>
       
                                            <td>
                                                <%= data[i].accountcode%>
                                            </td>
                                            <td>
                                                <%= data[i].src%>
                                            </td>
                                            <td>
                                                <%= data[i].dst%>
                                            </td>
                                            <td>
                                                <%= data[i].clid%>
                                            </td>
                                            <td>
                                                <%= data[i].uid%>
                                            </td>
                                            <td>
                                                <%= data[i].uid_name%>
                                            </td>

                                            <td>

                                                <%= data[i].calldate%>

                                            </td>

                                            <td>
                                                <%= data[i].end%>
                                            </td>
                                            <td>
                                                <%= data[i].billsec%>
                                            </td>
                                            <td>
                                                <%= data[i].disposition%>
                                            </td>

                                        </tr>
                                        <% } %>
                                </tbody>

 var table = $('#table_id').DataTable( {
        processing: true,
        serverSide: true, 
        ajax: {
        type: "GET",
        url: "cdr",
        columns: [
      {"data": "Original CLI"},
      {"data": "Source"},
      {"data": "Destination"},
      {"data": "Caller ID"},
      {"data": "Exten"},
      {"data": "Agent Name"},
      {"data": "Call Start"},
      {"data": "Call End"},
      {"data": "Duration"},
      {"data": "Call State"},
    
    ] }

and I keep getting these printed on the terminal

GET /pbx/cdr?draw=1&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=1&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex...etc

any help is highly appreciated.

Thanks in advance
Ucin

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin
    Answer ✓

    Hi Ucin,

    Our Editor NodeJS libraries are open source under the MIT license and support server-side processing, so one option is to use them. datatables.net-editor-server is the package in question.

    Documentation for it is available here.

    I'd also suggest reading over this blog post which details how you can use the Editor NodeJS libraries to add server-side processing.

    Allan

  • ucinucin Posts: 13Questions: 4Answers: 0

    Hello Allan,

    Thanks for your reply. I'll lookin to this.

    Thanks again,
    Ucin

  • ucinucin Posts: 13Questions: 4Answers: 0

    Hi Allan,

    I tried using the editor version and it's all good but that only a trial version? Event if I opt-out of using the editor (when selecting from the generator) it still says trial. Can you clarify this please .

    if I don't use it , I still haven't figured out how to implement the whole thing. Like how can I see what is being requested, I console.log req.query, body but nothing is showing. Most probably it's because of my lack of knowledge, but maybe if I could find out what is really being requested maybe I can respond with something and take it from there.

    Thanks again,
    Ucin

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    The server-side libraries for Editor are open source under the MIT license, as Allan explained above. The trial restriction is only on the client-side (browser) so those scripts will be fine to use.

    Colin

This discussion has been closed.