Set Custom id for every cell

Set Custom id for every cell

cent89cent89 Posts: 19Questions: 6Answers: 0
edited December 2018 in Free community support

Hi,
I have a table ("subscriptions") with the list of user subscribed to a site; I have attached to this table some columns: the number is dynamic.
The values of this colums ara taken from another table, where I have the id of the columns and the value (and the row id as primary key). So, any cells in the rendered table have a "custom" id, not the row id.
In the php controller, after the main sql to subscriptions table, I have a loop that add a column and for every row it search the correct value in the db: for 3 lines and 2 columns like below, I have the main sql and other 6 query.

How I can set, in the editor, the cell's id so when I edit the cell the controller can edit the correct value?

--------------------------------------------------------------------------
|| Id_row | Username |       Col_A      |       Col_B     | ....||
-------------------------------------------------------------------------
||  1        | Frank         | a (cell.id = 1) | b (cell.id = 2) | ...||
||  2        | Mario         | c (cell.id = 3) | d (cell.id = 4) | ...||
||  3        | Frank         | e (cell.id = 5) | e (cell.id = 6) | ...||
-------------------------------------------------------------------------

Thanks!
Roberto

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @cent89 ,

    This looks like the join table in the example here. Have you tried implementing like this?

    Cheers,

    Colin

  • cent89cent89 Posts: 19Questions: 6Answers: 0

    Hi,
    I can't use joins: for one subscriptions row, i have moltiple rows (one for every columns) in a "specifications" table.
    I have already done the render of the datatable, the problem is the editor...

    Thanks!
    Roberto

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Hi Roberto,

    You would need to use a standalone Editor such as this. The DataTables configured Editor will not work the way you are looking to use it.

    Allan

  • cent89cent89 Posts: 19Questions: 6Answers: 0

    Sounds good.
    But in my case in one panel/row table I have multiple fileds with the same name "value".
    So, in the sql data I can rename the name, but when I create the editor, somethings goes wrong.
    Some code:

    PHP (Laravel controller)

    ...
    $builder = Iscrizione::query()
        ->select('iscrizione.*', 'opz_1.valore as opz_1', 'opz_2.valore as opz_2', 'opz_3.valore as opz_3', 'opz_4.valore as opz_4')
        ->where('id_servizio', $input['id_servizio']);
        foreach($opzioni as $opzione){
          $builder->leftJoin('opzione_valore as opz_'.$opzione->id, function($join) use ($opzione){
            $join->on('opz_'.$opzione->id.'.id_iscrizione', '=', 'iscrizione.id');
            $join->where('opz_'.$opzione->id.'.id_opzione', $opzione->id);
          });
        }
        $builder->orderBy('iscrizione.created_at', 'DESC');
    
        return $datatables->eloquent($builder)->toJson();
    

    JS

    //editor 
    ajax: {
          url: "{{route('opzione_valore.index')}}"
        },
        display: "lightbox",
        table: "#iscrizioneTable",
        fields: [
          {label: "Opzione 1", name: "opz_1"},
          {label: "Opzione 2", name: "opz_2"},
          //...
        ]
    ...
    
    $('#iscrizioneTable').DataTable({
        dom: 'Bfrtip',
        responsive: true,
        processing: true,
        serverSide: true,
        language: { "url": "{{ asset('Italian.json') }}" },
        ajax: "{!! route('iscrizione.data', ['id_servizio' => $servizio->id]) !!}",
        columns: [{data: 'opz_1'}, {data: 'opz_2'}],
    }
    
    
  • cent89cent89 Posts: 19Questions: 6Answers: 0

    Mmmm...
    I have build a Standalone editor, with a simple html table.
    I can open the editor when I click on the "Edit" button but I'm getting ad error when I save the record:

    OpzioneValoreDataTableEditor::editRules() must be an instance of Illuminate\\Database\\Eloquent\\Model, null given.
    

    Logging the data with a preSubmit(), the data field is an Object, not in json format:

    {action:'edit', data: {[object Object]}.
    

    The code in a cell table is:

    <div data-editor-id=8><span data-editor-field='valore'>Valore da modificare</span> <button id='editor_edit'>Edit</button></div>
    

    Can you help me? Thanks!

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    OpzioneValoreDataTableEditor::editRules() must be an instance of Illuminate\Database\Eloquent\Model, null given.

    I'm not familiar with that code I'm afraid. It sounds like an unhandled null, but I'm not sure. Possibly it might be caused by:

    {action:'edit', data: {[object Object]}.

    Could you give me a link to the page showing that so I can take a look and see what is going wrong?

    Thanks,
    Allan

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    I'm getting:

    DataTables warning: table id=iscrizioneTable - Requested unknown parameter 'id' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

    when I load that page. Is that not what you are seeing?

    Allan

  • cent89cent89 Posts: 19Questions: 6Answers: 0

    Ok, It's the row id, not the cell id. Even if I add the correct id, the error in the console is the same:

    DataTableEditor::editRules() must be an instance of Illuminate\Database\Eloquent\Model, null given

    Thanks,
    Roberto

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    That's still an error in the server-side code that you are using, and I'm not sure what that is. I'm also still getting a tn/4 error when I load the link above, so I'm not sure how to recreate the error.

    Allan

This discussion has been closed.