How can add custom column in array

How can add custom column in array

tejeltejel Posts: 1Questions: 1Answers: 0
edited December 2017 in Free community support

Hello, I have string which want to delimiter with row and columns, also add custom column for checkbox functions:

Oleg\tGagarin\tMoscow\tCEO\r\nMax\tStanislavov\tPiter\tSEO\r\nMasha\tDarova\tLondon\tCFO\r\nAlex\tKukushkin\tBerlin\tCoder\r\n
Where \r\n is is delimiter for row
Where \t is is delimiter for columns

My output is

[data] => Array
(
    [0] => Array
        (
            [0] => Sasha
            [1] => Kukushkin
            [2] => Moscow
            [3] => CEO
        )
 
    [1] => Array
        (
            [0] => Oleg
            [1] => Gazmanov
            [2] => Piter
            [3] => SEO
        )
 
    [2] => Array
        (
            [0] => Masha
            [1] => Darina
            [2] => London
            [3] => Sales
        )
)

It's work well, but I add checkboxes function
https://www.gyrocode.com/projects/jquery-datatables-checkboxes/

Where checkox is first column, next I must add in my array [id] = > {key}

$data_decode_row = explode('\r\n', $data['users_result']);
$data_explode_colm = array();

foreach($data_decode_row as $d_k => $d_v){
    $data_explode_colm[$d_k] = explode('\t', $d_v);
    $result = array();
    foreach($data_explode_colm as $e_k => $e_v){
          $result['data'][$e_k]['id'] = $e_k;
          $result['data'][$e_k] = $e_v;
    }
}

But print_r is not shoe me ['id']

Any ideas?

var table_type = $(this).data('table');
var group_id = $(this).data('id');

// DataTable
var table = $('.UsersResultTable.'+table_type+'').DataTable({
  retrieve: true,
  ajax: {
    url: "/ajax/GetUsers",
    type: "POST",
    data : {
        group_id : group_id
    },
  },
  deferRender: true,
  sDom: 'rtlfip',
  // bFilter: false,
  columnDefs: [
     {
        compact: true,
        targets: 0,
        checkboxes: {
           selectRow: true
        }
     }
  ],
  select: {
     style: 'multi'
  },
  order: [[1, 'asc']]
});

Thanks.

Answers

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    My guess is that you need to pass by reference, but really this is a PHP question and not a DataTables one, so StackOverflow or similar is a better for general programming questions.

    Allan

  • bayibayi Posts: 2Questions: 0Answers: 0
    edited December 2017

    Ok, but I can to set first key ['id'] But DataTable is output JS alert error #1, I think because in my array key is int, and when I set string name...
    How can fix this? Any ideas?

    DataTables warning: table id=DataTables_Table_0 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

  • bayibayi Posts: 2Questions: 0Answers: 0

    Update: I fix alert error.
    From PHP ['id'] this is first element (test with print_r($result);, but when load data with AJAX ['id'] is move to last element, because key this is string, so how I can use my data with my JS...

This discussion has been closed.