Concat datatable field, with serverside search.

Concat datatable field, with serverside search.

KarlogKarlog Posts: 9Questions: 4Answers: 0
edited August 2017 in Free community support

Hello

I have some trouble getting CONCAT to work on the my table, while still having the field searchable (server-side-processing).

For the editor I used:

Field::inst( 'hours.project' )
    ->validator( 'Validate::notEmpty' )
        ->validator( 'Validate::required' )
        ->options( Options::inst()
        ->table( 'projects' )
        ->value( 'id' )
        ->label( array('id', 'name') )
),

But when I try to use the render function in the javascript, search starts complaining.

I would like to concat the project id with its name.

Lattest attempt that gives me the expected layout

......
{ data: null, 
        render: function ( data, type, row ) {
            // Combine the first and last names into a single table field
            return data.hours.project+' '+data.projects.name;
        } 
},
.....

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin
    Answer ✓

    The problem here is that you have data: null which means that the server-side doesn't know what the information in the column is (since it could be anything - it is client-side rendered).

    What you'll need to do for this is to have one column with data: 'hours.project' and another hidden column (columns.visible) with data: 'projects.name. You can still use the renderer on the visible column to show them together.

    Allan

  • KarlogKarlog Posts: 9Questions: 4Answers: 0
    edited August 2017

    Thanks for the fast reply, but I can't quite get it to work.

    I have changed my js to:

    .........},
    { 
          "data": "hours.project", 
          render: function ( data, type, row ) {
                // Combine the first and last names into a single table field
                return data.hours.project + ' ' + data.projects.name;
          } 
    },
    {
          "data": "projects.name",
          "visible": false
    },
    {....
    

    the hours.project is a fk-key to the table 'projects'

    the json before the change looks like:

    {"data":[{"DT_RowId":"row_132","hours":{"user":"7","work_type":"8","project":"24","start":"2017-08-14 07:00:00","stop":"2017-08-14 14:30:00","invalid":"0","timestamp":"2017-08-15 17:07:26","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"test type 1"},"projects":{"name":"Opl\u00e6ring af l\u00e6ring"}},{"DT_RowId":"row_145","hours":{"user":"8","work_type":"7","project":"14","start":"2017-08-25 11:56:54","stop":"2017-08-25 11:56:57","invalid":"0","timestamp":"2017-08-25 11:56:57","price_per_hour":"250"},"users":{"initials":"JAN"},"work_type":{"name":"Intern"},"projects":{"name":"Vedligeholdelse af egne maskiner"}},{"DT_RowId":"row_146","hours":{"user":"8","work_type":"2","project":"98","start":"2017-08-25 11:56:57","stop":"2017-08-25 23:59:59","invalid":"0","timestamp":"2017-08-25 23:59:59","price_per_hour":"0"},"users":{"initials":"JAN"},"work_type":{"name":"Pause"},"projects":{"name":"Pause"}},{"DT_RowId":"row_147","hours":{"user":"7","work_type":"10","project":"106","start":"2017-08-25 10:26:19","stop":"2017-08-25 12:26:24","invalid":"0","timestamp":"2017-08-25 12:26:33","price_per_hour":"550"},"users":{"initials":"BKM"},"work_type":{"name":"Udvikling"},"projects":{"name":"Udvikling af timeregistering, someol"}},{"DT_RowId":"row_148","hours":{"user":"7","work_type":"8","project":"106","start":"2017-08-25 12:26:44","stop":"2017-08-25 12:30:45","invalid":"0","timestamp":"2017-08-25 12:30:45","price_per_hour":"123"},"users":{"initials":"BKM"},"work_type":{"name":"test type 1"},"projects":{"name":"Udvikling af timeregistering, someol"}},{"DT_RowId":"row_149","hours":{"user":"7","work_type":"2","project":"98","start":"2017-08-25 12:30:45","stop":"2017-08-25 13:35:39","invalid":"0","timestamp":"2017-08-25 13:35:39","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"Pause"},"projects":{"name":"Pause"}},{"DT_RowId":"row_150","hours":{"user":"7","work_type":"8","project":"106","start":"2017-08-25 13:35:39","stop":"2017-08-25 13:39:46","invalid":"0","timestamp":"2017-08-25 13:39:46","price_per_hour":"123"},"users":{"initials":"BKM"},"work_type":{"name":"test type 1"},"projects":{"name":"Udvikling af timeregistering, someol"}},{"DT_RowId":"row_151","hours":{"user":"7","work_type":"2","project":"98","start":"2017-08-25 13:39:46","stop":"2017-08-25 15:48:55","invalid":"0","timestamp":"2017-08-25 15:48:55","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"Pause"},"projects":{"name":"Pause"}},{"DT_RowId":"row_152","hours":{"user":"7","work_type":"8","project":"106","start":"2017-08-25 15:48:55","stop":"2017-08-25 16:14:00","invalid":"0","timestamp":"2017-08-25 16:14:00","price_per_hour":"123"},"users":{"initials":"BKM"},"work_type":{"name":"test type 1"},"projects":{"name":"Udvikling af timeregistering, someol"}},{"DT_RowId":"row_153","hours":{"user":"7","work_type":"2","project":"98","start":"2017-08-25 16:14:00","stop":"2017-08-25 23:59:59","invalid":"0","timestamp":"2017-08-25 23:59:59","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"Pause"},"projects":{"name":"Pause"}},{"DT_RowId":"row_144","hours":{"user":"8","work_type":"7","project":"16","start":"2017-08-25 11:41:54","stop":"2017-08-25 11:56:54","invalid":"0","timestamp":"2017-08-25 11:56:54","price_per_hour":"250"},"users":{"initials":"JAN"},"work_type":{"name":"Intern"},"projects":{"name":"Vedligeholdelse af egne lokaler"}},{"DT_RowId":"row_143","hours":{"user":"7","work_type":"7","project":"12","start":"2017-08-25 11:41:48","stop":"2017-08-25 12:26:44","invalid":"0","timestamp":"2017-08-25 12:26:44","price_per_hour":"250"},"users":{"initials":"BKM"},"work_type":{"name":"Intern"},"projects":{"name":"El Polering"}},{"DT_RowId":"row_142","hours":{"user":"7","work_type":"7","project":"11","start":"2017-08-22 15:54:18","stop":"2017-08-22 23:59:59","invalid":"0","timestamp":"2017-08-22 23:59:59","price_per_hour":"250"},"users":{"initials":"BKM"},"work_type":{"name":"Intern"},"projects":{"name":"Fremstilling af varer til lager"}},{"DT_RowId":"row_133","hours":{"user":"7","work_type":"8","project":"24","start":"2017-08-15 07:00:00","stop":"2017-08-15 14:30:00","invalid":"0","timestamp":"2017-08-15 17:07:26","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"test type 1"},"projects":{"name":"Opl\u00e6ring af l\u00e6ring"}},{"DT_RowId":"row_134","hours":{"user":"7","work_type":"8","project":"24","start":"2017-08-16 07:00:00","stop":"2017-08-16 14:30:00","invalid":"0","timestamp":"2017-08-15 17:07:26","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"test type 1"},"projects":{"name":"Opl\u00e6ring af l\u00e6ring"}},{"DT_RowId":"row_135","hours":{"user":"7","work_type":"8","project":"24","start":"2017-08-17 07:00:00","stop":"2017-08-17 14:30:00","invalid":"0","timestamp":"2017-08-15 17:07:26","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"test type 1"},"projects":{"name":"Opl\u00e6ring af l\u00e6ring"}},{"DT_RowId":"row_136","hours":{"user":"7","work_type":"8","project":"24","start":"2017-08-18 07:00:00","stop":"2017-08-18 14:00:00","invalid":"0","timestamp":"2017-08-15 17:07:26","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"test type 1"},"projects":{"name":"Opl\u00e6ring af l\u00e6ring"}},{"DT_RowId":"row_137","hours":{"user":"7","work_type":"2","project":"98","start":"2017-08-15 17:07:43","stop":"2017-08-16 17:07:45","invalid":"0","timestamp":"2017-08-15 17:07:48","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"Pause"},"projects":{"name":"Pause"}},{"DT_RowId":"row_138","hours":{"user":"7","work_type":"7","project":"10","start":"2017-08-17 16:33:57","stop":"2017-08-17 16:34:07","invalid":"0","timestamp":"2017-08-17 16:34:07","price_per_hour":"250"},"users":{"initials":"BKM"},"work_type":{"name":"Intern"},"projects":{"name":"Lager"}},{"DT_RowId":"row_139","hours":{"user":"7","work_type":"2","project":"98","start":"2017-08-17 16:34:07","stop":"2017-08-17 16:34:18","invalid":"0","timestamp":"2017-08-17 16:34:18","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"Pause"},"projects":{"name":"Pause"}},{"DT_RowId":"row_140","hours":{"user":"7","work_type":"7","project":"10","start":"2017-08-17 16:34:18","stop":"2017-08-17 16:34:33","invalid":"0","timestamp":"2017-08-17 16:34:33","price_per_hour":"250"},"users":{"initials":"BKM"},"work_type":{"name":"Intern"},"projects":{"name":"Lager"}},{"DT_RowId":"row_141","hours":{"user":"7","work_type":"9","project":"102","start":"2017-08-17 16:34:33","stop":"2017-08-17 16:35:07","invalid":"0","timestamp":"2017-08-17 16:35:07","price_per_hour":"123"},"users":{"initials":"BKM"},"work_type":{"name":"test type 2"},"projects":{"name":"test 2"}},{"DT_RowId":"row_154","hours":{"user":"7","work_type":"2","project":"98","start":"2017-08-29 01:14:17","stop":null,"invalid":"0","timestamp":"2017-08-29 01:14:17","price_per_hour":"0"},"users":{"initials":"BKM"},"work_type":{"name":"Pause"},"projects":{"name":"Pause"}}],"options":{"hours.user":[{"label":"ALAN","value":"49"},{"label":"BKM","value":"7"},{"label":"JAN","value":"8"},{"label":"test","value":"48"}],"hours.work_type":[{"label":"Afspadsering","value":"6"},{"label":"Alle arbejdstyper","value":"3"},{"label":"Ferie","value":"4"},{"label":"Fri uden l\u00f8n","value":"1"},{"label":"Intern","value":"7"},{"label":"Pause","value":"2"},{"label":"Sygdom","value":"5"},{"label":"Udvikling","value":"10"},{"label":"test type 1","value":"8"},{"label":"test type 2","value":"9"}],"hours.project":[{"label":"1 Fri","value":"1"},{"label":"10 Lager","value":"10"},{"label":"100 Ghh","value":"100"},{"label":"101 test linda","value":"101"},{"label":"102 test 2","value":"102"},{"label":"103 test 3","value":"103"},{"label":"104 test 3","value":"104"},{"label":"105 test 4","value":"105"},{"label":"106 Udvikling af timeregistering, someol","value":"106"},{"label":"11 Fremstilling af varer til lager","value":"11"},{"label":"12 El Polering","value":"12"},{"label":"13 Inddamper","value":"13"},{"label":"14 Vedligeholdelse af egne maskiner","value":"14"},{"label":"15 Vedligeholdelse af udend\u00f8rs arealer","value":"15"},{"label":"16 Vedligeholdelse af egne lokaler","value":"16"},{"label":"17 Oprydning \/ Reng\u00f8ring","value":"17"},{"label":"18 Vedligeholdelse af tegninger","value":"18"},{"label":"19 Tilbudstegninger \/ Beregning","value":"19"},{"label":"2 Ferie ","value":"2"},{"label":"20 Bestilling & Leverand\u00f8r","value":"20"},{"label":"21 Pakke pakker til forsendelse","value":"21"},{"label":"22 Rejse & Service","value":"22"},{"label":"23 K\u00f8rsel ","value":"23"},{"label":"24 Opl\u00e6ring af l\u00e6ring","value":"24"},{"label":"25 Skabelon & V\u00e6rkt\u00f8j","value":"25"},{"label":"3 Skole \/ Kursus ","value":"3"},{"label":"4 Afspadsering \/ Flex","value":"4"},{"label":"5 Sygdom","value":"5"},{"label":"6 Interne m\u00f8der","value":"6"},{"label":"98 Pause","value":"98"},{"label":"99 System","value":"99"}]},"files":[],"draw":1,"recordsTotal":"23","recordsFiltered":"23"}
    
  • KarlogKarlog Posts: 9Questions: 4Answers: 0

    Looks like it was another field that was blocking, I will post my javascript when I fix that issue so that others can use it.

  • gabriel231gabriel231 Posts: 1Questions: 0Answers: 0

    have u solve this?

This discussion has been closed.