Error when using a null column for rendering

Error when using a null column for rendering

globalplaneglobalplane Posts: 70Questions: 12Answers: 0

Link to test case: https://comprehensibleinputwiki.com/cure_finder/public/test_case.php
Debugger code (debug.datatables.net): ebuyeb
Error messages shown: DataTables warning: table id=cures - Unknown field: (index 2)
Description of problem:

I'm using the PHP library to grab some columns from MySQL. On the client side, I would like to combine two of the columns into one dataset column. It seems to work when first loading the page, but as soon as I type anything in the search box, it gives the above error. The request to the server seems to include a blank column even though I put data: null.

Please let me know if there are other issues with the way I am doing this.

Here is my server side code:

<?php
include( "./editor/lib/DataTables.php" );
 
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

Editor::inst( $db, 'RC_final', 'index' )
    ->debug(true)
    ->fields(
        Field::inst( 'comment_id' ),
        Field::inst( 'link_id' ),
        Field::inst( 'body' ),
        Field::inst( 'probability_of_1' )
    )
    ->process( $_POST )
    ->json();


<?php
>
```
?>


And the client side html:
```html
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="./datatables/datatables.min.css" />
        <script src="./datatables/datatables.min.js"></script>
    </head>
<body>
    <table id="cures" class="display" style="width:100%">
        <thead>
            <tr>
                <th>#</th>
                <th>#</th>
                <th>Link</th>
                <th>Text</th>
                <th>Probability</th>
            </tr>
        </thead>
    </table>

    <script>
        new DataTable('#cures', {
            ajax: {
                url: 'datatables/server_processing.php',
                type: 'POST'
            },
            columns: [
                {
                    data: 'link_id'
                },
                {
                    data: 'comment_id'
                },
                {   
                    data: null,
                    render: function (data, type, row) {
                        var link = row.link_id + " " + row.comment_id;
                        return link;
                    }
                },
                {data: 'body'},
                {data: 'probability_of_1'}
            ],
            "columnDefs": [
                { "visible": false, "targets": [0, 1] }
            ],
            serverSide: true,
            dom: 'Qlfrtip'
        });
        </script>
</body>
</html>

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,990Questions: 1Answers: 10,367 Site admin
    Answer ✓

    The issue is that you have server-side processing enabled, and a client-side created / rendered colum.

    So when you attempt to search or sort on the link column the server doesn't know what to do, since the column doesn't exist there. Could you change data: null to be data: 'link_id' which would stop the error. It would mean search / sort on that column would be done on that property. Or use columns.searchable / columns.orderable to disable those actions on that column.

    Allan

  • globalplaneglobalplane Posts: 70Questions: 12Answers: 0

    Oh that makes sense, thanks!

Sign In or Register to comment.