how to use the data of nested objects (arrays) in server-side processing

how to use the data of nested objects (arrays) in server-side processing

AndriiFKAndriiFK Posts: 5Questions: 1Answers: 0

how to use the data of nested objects (arrays) in server-side processing, or is it possible to somehow refer to two columns in one $('#myTable').DataTable({
'ajax': {
url: '/fetchData.php',
},
'columns':[
{
data: 'file',
},
{
data: 'name', data: 'id', <============ ???
render: function(data, ... ???... type, row)
},
'processing': true,
'serverSide': true
});

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    You can't define two columns.data for the same column.

    This example shows how to display nested objects.

    This example shows how to combine row data to be displayed in one column.

    If this doesn't help then please post an example of your JSON data from the browser's network inspector tool. Tell us how you want it displayed.

    Kevin

  • AndriiFKAndriiFK Posts: 5Questions: 1Answers: 0

    as I understand these Ajax applications. but I asked about the ServerSide method

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Kevin is correct - use a rendering method on the client-side to combine two data points returned from the server. There is an example of that available here - the first_name and last_name properties returned from the server are combined to be shown in the first column.

    If you wanted to combine the data at the server-side, you'd need to modify whatever fetchData.php is doing.

    Allan

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Just to make sure I understand your question:

    You are getting a JSON response from the server, using server side processing, and want to display the returned data in a certain way. Is this correct? If yes then the above answers still apply.

    Kevin

  • AndriiFKAndriiFK Posts: 5Questions: 1Answers: 0

    json ajax

    creating a table ajax

    It works but rendering is slow and server side rendering is very fast. So I want to do it on the server side , but I can't pass several parameters to the rendering of that column
    because the json file has a different look

    creating a table SERVER SIDE

    how should I pass two DATA parameters in the column ?

  • AndriiFKAndriiFK Posts: 5Questions: 1Answers: 0

    if for ajax I create a corresponding json file, then for the method on the server side I do not understand how to edit fetchdata.php so that the json file at the output is in the desired form

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    Use:

    data: 's_opys'
    render: function (data, type, row) {
    
    }
    

    With that data will be whatever the value of s_opys is. The row property is the data object for the row - i.e. s_opys === row.s_opys. So you'd use row.id to get the id for the row, etc.

    Allan

  • AndriiFKAndriiFK Posts: 5Questions: 1Answers: 0

    Thank you very much. I forgot something about it.

Sign In or Register to comment.