AutoFill with Editor doesn't work

AutoFill with Editor doesn't work

M_ModeM_Mode Posts: 4Questions: 0Answers: 0
edited June 2016 in Free community support

Hello,

I use autofill with the editor, but on changes with autofill, the server side script will not be called.

Info: I use the newest nightly from all extensions and from the editor i use the trial version.

Here is my code:

var editor = new $.fn.dataTable.Editor( {
            "ajax" : "./ajax/script.php",
            "table": "#datatable_articles",
            "idSrc":  'articleID',
            "fields": [
                        //... my fields
            ]
} );

var otable = $('#datatable_articles').DataTable({
            // ... settings
            "autoFill": {
                        editor:  editor
            },
            "bProcessing": false,
            "sAjaxSource": urlAction,
            // ... more settings
});

Replies

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Can you give me a link to a test page showing the issue please? It appears to work okay in this example.

    Allan

  • M_ModeM_Mode Posts: 4Questions: 0Answers: 0

    Hello, i have found the bug.

    If you use "idSrc" in the editor and your data hasen't the "DT_RowId" in the array, then the editor doesn't call the ajax (create, update, delete) script.

    If "DT_RowId" in the data available, then you can use the "idSrc" (even it makes no sense) and the update works. I think is is a bug in the autoFill script or in the editor.

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Could you try setting the rowId property in DataTables to match whatever your Editor idSrc option is please?

    If you could show me a sample of your data and the full initialisation you are using I'll try to recreate the issue.

    To be honest, I would be surprised if the idSrc had an effect on AutoFill since it uses nodes to tell Editor what rows / cells to edit, rather than id values.

    Thanks,
    Allan

  • M_ModeM_Mode Posts: 4Questions: 0Answers: 0
    edited June 2016

    Ah okay,

    if i set the rowId, it works without problems.

    This is the configuration, which make problems (only the important things.):

    Editor:

    var editor = new $.fn.dataTable.Editor( {
                "ajax": {
                            create: {
                                        url:  "./ajax/rest-action-sell-pricecontrol-update.php"
                         },
                         edit: {
                                    url:  "./ajax/rest-action-sell-pricecontrol-update.php"
                         },
                         remove: {
                                     url:  "./ajax/rest-action-sell-pricecontrol-update.php"
                         }
                },
                "table": "#datatable_articles",
                "idSrc":  'sku',
                "fields": [
                            {
                                        "label": "category:",
                                        "name": "category"
                            },
                            // .....
                     ]
    } );
    

    Datatable:
    - no rowId

    var otable = $('#datatable_articles').DataTable({
          // ....
          "aoColumnDefs": [
          {
                "bSortable": false,
                "aTargets": 0,
                "data": null,
                "defaultContent": '<label class="checkbox-inline"><input            type="checkbox" class="checkbox style-0"><span></span></label>'
          },
          {
                "aTargets": 1,
                "className": "editable",
                "data": "category"
          },
          {
                "aTargets": 2,
                "data": "sku"
          },
                // .....
          ],
          "bProcessing": false,
          "sAjaxSource": "myURL",
          "destroy": true,
          "autoFill": {
                columns: '.editable',
                editor:  editor
          },
          // ...
    });
    

    Array from the PHP:

    $returnDataArray = array();
    $returnDataArray[] = null; // for the check box
    $returnDataArray["category"] = $category;
    $returnDataArray["sku"] = $key;
    
    $returnDataParentArray[] = $returnDataArray;
    $returnArray = array("data"  => $returnDataParentArray);
        
    echo json_encode($returnArray);
    
  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    That's fantastic - thanks. Good to hear you've got it working with the rowId option. I'll take a look into this and try to determine what is going wrong without it - it shouldn't be required I don't think.

    Allan

  • electricpollenelectricpollen Posts: 1Questions: 0Answers: 0
    edited July 2016

    I encountered this as well. The docs do describe the difference between idSrc and rowId but I latched onto idSrc and didn't see rowId until the code's use of id() pointed me to it. It's a subtle difference between the two. I didn't see this posting until after I had dug into the code. So, for what it's worth, AutoFill requires rowId at "var id = dt.row( cell.index.row ).id();" near the bottom of AutoFill's _editor function

This discussion has been closed.