0

I am using jQuery datatable in my php code.

my server server-side processing script here

$columns = array(
    array( 'db' => 'val1', 'dt' => 0 ),
    array( 'db' => 'val2',  'dt' => 1 ),
);

here problem is that how i get another unbound column val3 which have value of val1+val2 .

Example :

val1 val2 val3
1    2    3
3    5    8

here val1 and val2 is database column and val3 is calculated column.

I am stuck right now that how to add val3 column from server-side script.

Any help is appreciated.

1 Answer 1

1
  1. You need to write DB query from server side for getting 3rd column.

  2. Client side keep 3 columns table code (html)

    <table class="table results" border="1">
        <thead>
            <tr>
                <th>val1</th>
                <th>val2</th>
                <th>val3</th>
            </tr>
        </thead>
    </table>
    
  3. Client side define 3 columns (jquery datatable)

    results= $(".results").dataTable({
        aLengthMenu: [ [10, 25, 50, 100, 150, "-1"], [10, 25, 50, 100, 150, "All"] ],
        iDisplayLength: 10,
        searching: true,
        "aaSorting": [],
        "order": [[ 0, "desc" ]],
        "sPaginationType": "full_numbers",
    
        "bProcessing": true,
        "serverSide": true,
        "bDestroy": true,
        "cache": false,
        "sAjaxSource": "<?php echo $serverside_php; ?>",
    
        "sDom": 'T<>lfrtip',
        "oTableTools": {
            "sRowSelect": "os",
            "aButtons": [ "select_all", "select_none" ]
        },
    
        "aoColumnDefs": [
            { "bSortable": false },
            { "data": "val1" },
            { "data": "val2" },
            { "data": "val3" },
        ],
    });
    
  4. Feed the server side response data to client datatable + html

Sign up to request clarification or add additional context in comments.

1 Comment

Seems like my link is broken, anyhow write a query which will give you 3 columns the way you want where last column would be sum of first two and feed the values to table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.