Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82520

How to merge 2 json properties into 1 column

$
0
0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Reading https://datatables.net/manual/data/renderers and wondering how to merge 2 json properties into 1 column.

Let's say I have this data

courseSubjectDescription => Math is great
termCodeDescription => Term 1
courseId => 123
courseTitle => Math 101
courseDescription => Very hard course
courseYear => 2024

This code works

  new DataTable('#example', {
    ajax: {
        url: 'data.json',
        dataSrc: ''
    },
    columns: [
        { data: 'courseSubjectDescription' },
        { data: 'termCodeDescription' },
        { data: 'courseId' },
        { data: 'courseTitle' },
        { data: 'courseDescription' }
    ]
});

Output:

[Math is great] [Term 1] [123] [Math 101] [Very hard course] => 5 cols

Now I want to merge data: 'courseId' with data: 'courseYear'

  new DataTable('#example', {
    ajax: {
        url: 'data.json',
        dataSrc: ''
    },
    columns: [
        { data: 'courseSubjectDescription' },
        { data: 'termCodeDescription' },
        { data: 'courseId'},
        { data: 'courseId' + '-' + 'courseYear' },  <=whats the correct syntax??
        { data: 'courseDescription' }
    ]
});

Desired Output:

[Math is great] [Term 1] [123-2024] [Math 101] [Very hard course] => 5 cols

How do I achieve that?

Tried below unsuccessfully.

{data: null,
     render: function ( data, type, row ) {
        return data.courseId +' -'+ data.courseTitle;
    },

and

 { data: null,
    render: function ( data, type, row ) {
        return ('row.courseId' + '-' + 'row.courseYear');
    },

Thanks


Viewing all articles
Browse latest Browse all 82520

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>