How can i combine two or more fields in serverside script in datatable as one json return

How can i combine two or more fields in serverside script in datatable as one json return

Aryan1703Aryan1703 Posts: 73Questions: 19Answers: 1

Suppose i have three fields here but i want to return them as one object. Ihave done similar thing but in these i am directly getting them as json object from my database as I have created a view for it, but I want it to be done in the script.

This is what i am doing I wan to do same for individual fields

  Field::inst('V.controller', 'controller')
            ->getFormatter(function ($val, $data, $field) {
                $controller = json_decode($val, true); // Decode the JSON into an array
                $controllerReturn = isset($controller['controller']) ? $controller['controller'] : '';
                if (isset($controller['UpdatedBy'])) {
                    $controllerReturn .= '<br>& ' . $controller['UpdatedBy'];
                }
                return $controllerReturn;
            }),
Editor::inst( $db, 'datatables_demo' )
    ->fields(

        Field::inst( 'office' ),
        Field::inst( 'extn' ),
        Field::inst( 'age' ),``````
    )
    ->debug(true)
    ->process( $_POST )
    ->json();

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,441Questions: 1Answers: 10,459 Site admin

    Normally, I would suggest combining them on the client-side with a renderer like in this example.

    What is the specific use case for needing to combine them? Is it just for table display (in which case use a renderer), or something else?

    Allan

  • Aryan1703Aryan1703 Posts: 73Questions: 19Answers: 1

    I am doing it for filtering and want to use raw data( as i am using server-side true)

  • allanallan Posts: 63,441Questions: 1Answers: 10,459 Site admin
    Answer ✓

    Oh, in that case the VIEW you've created is the only option. Bu the time it is in the PHP script it is too late for the filtering, since that is done in SQL.

    Allan

Sign In or Register to comment.