How divide current row of one table between the two other tables

How divide current row of one table between the two other tables

VitalizVitaliz Posts: 71Questions: 7Answers: 1
edited October 2015 in Editor

Hi, all.
I have three tables: 'modx_vkrzayavka' , 'modx_vkrzakaz' and 'modx_vkrklient'. Then I open editor`s window with table
'modx_vkrzayavka', I need to create new rows in tables 'modx_vkrzakaz' and 'modx_vkrklient'. Some fields of table
'modx_vkrzayavka' will be written to created row of 'modx_vkrzakaz' table and others to 'klient' table.

The main problem I can't resolve is how select appropriate table, which is declared, but not active in this moment.
I can't find any suitable example, using the last versions of Datatables and Editor API.
Can you show me any working example for my case?
DT Debugger code is: oqubij

This question has an accepted answers - jump to answer

Answers

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1

    Make simple live test - try to add one row in table. Don`t working at all(.
    http://live.datatables.net/qiqizeka/1/

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Make live working example based on https://datatables.net/reference/api/row%28%29.remove%28%29 , but can't save it.;(((

    Question is closed.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Question is closed.

    Did you resolve this?

    What are you using for your server-side script here? Are you using the PHP or .NET libraries? Are you using joined tables?

    Allan

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Yes, I have resolve this. I use PHP libraries and main table with two joined.
    The most helpfull guide was https://datatables.net/examples/api/add_row.html
    It show simple method, how add new row in any table, using field values from variables.

    t.row.add( [
                counter +".1",
                counter +".2",
                counter +".3",
                counter +".4",
                counter +".5"
    
            ] ).draw( false );
    

    The main subtlety was that using t.row().add, as I tried before, don't working)))).

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    I tried to format code example, as you recommend,

    To highlight code snippets, use ``` before and after the code on newlines.

    I edit it four times,but it collapsed every time(((
    Don`t understand why...
    But in fifth time all is Ok.

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Hi, Allan.
    Much I hastened , saying the decision to issue. My code is not running.
    The main problem is to use multiple tables together. My code working only with HTML data, not with real data base via PHP lib.

    This is my code:
    js scripts for tables are included separately, as they was generated by Generator.

    <script type="text/javascript" charset="utf-8" src="js/table.modx_vkrzayavka.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/table.modx_vkrzakaz_sm.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/table.modx_vkrklient.js"></script>
    

    Main part of index.html:

    <div class="container">
    
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="#anket">Анкеты</a></li>
            <li><a data-toggle="tab" href="#zakaz">Заказы</a></li>
            <li><a data-toggle="tab" href="#sprklient">Клиенты</a></li>
        </ul>
    
        <div class="tab-content">
            <div id="anket" class="tab-pane fade in active">
                <div class="container">
    
                    <h3>
                        Анкета клиента
                    </h3>
    
                    <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="vkrzayavka" width="100%">
                        <thead>
                        <tr>
                            <th>Обр.</th>
                            <th>Студент</th>
                            <th>E-mail</th>
                            <th>Телефон</th>
                            <th>ВУЗ</th>
                            <th>Форма обучения</th>
                            <th>Откуда пришёл?</th>
                            <th>Специальность</th>
                            <th>Дисциплина</th>
                            <th>Преподаватель</th>
                            <th>Вид работы</th>
                            <th>Этап 1 </th>
                            <th>Этап 2</th>
                            <th>Этап 3</th>
                            <th>Этап 4</th>
                            <th>Этап 5</th>
                            <th>Этап 6</th>
                            <th>Этап 7</th>
                            <th>Тема работы</th>
                            <th>Предприятие</th>
                            <th>Есть доп. треб.?</th>
                            <th>Когда отдать?</th>
                            <th>Месяц защиты</th>
                            <th>Сколько страниц?</th>
                            <th>Предоставите ли вы отчетность предприятия?</th>
                            <th>Eсть план?</th>
                            <th>Cфера деятельности</th>
                        </tr>
                        </thead>
                    </table>
    
                </div>
            </div>
            <div id="zakaz" class="tab-pane fade">
    
                <div class="container">
    
                    <h3>Активные заказы</h3>
    
                    <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="modx_vkrzakaz" width="100%">
                        <thead>
                        <tr>
                            <th>№ заказа</th>
                            <th>Клиент</th>
                            <th>Автор</th>
                            <th>Вид заказа</th>
                            <th>Тема заказа</th>
                            <th>Этап 1</th>
                            <th>Этап 2</th>
                            <th>Этап 3</th>
                            <th>Этап 4</th>
                            <th>Этап 5</th>
                            <th>Этап 6</th>
                            <th>Этап 7</th>
                            <th>Сумма заказа</th>
                            <th>Оплачено</th>
                        </tr>
                        </thead>
                    </table>
    
                </div>
            </div>
            <div id="sprklient" class="tab-pane fade">
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="modx_vkrklient" width="100%">
                <thead>
                <tr>
                    <th>ФИО</th>
                    <th>E-mail</th>
                    <th>Логин</th>
                    <th>Пароль</th>
                    <th>Телефон</th>
                    <th>ВУЗ</th>
                    <th>Форма обучения</th>
                    <th>Специальность</th>
                    <th>Соцсети</th>
                    <th>Дополнительная информация</th>
                    <th>Город</th>
                </tr>
                </thead>
            </table>
            </div>
        </div>
    </div>
    

    js script, there I try to divide incomming data between three tables is table.modx_vkrzayavka.js
    This code is placed in $.fn.dataTable.Buttons function.

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015
    $(document).ready(function() {
        var editor = new $.fn.dataTable.Editor( {
            ajax: 'php/table.modx_vkrzayavka.php',
            table: '#vkrzayavka',
            i18n: { ....},
            fields: [
                {
                    "label": "Обработано",
                    "name": "modx_vkrzayavka.obr",
                    "type": "hidden"
                },
    // this fields are used in modx_vkrklient row creating
                {
                    "label": "\u0421\u0442\u0443\u0434\u0435\u043d\u0442",
                    "name": "modx_vkrzayavka.fio"
                },
                {
                    "label": "E-mail",
                    "name": "modx_vkrzayavka.toemail"
                },
                {
                    "label": "\u0422\u0435\u043b\u0435\u0444\u043e\u043d",
                    "name": "modx_vkrzayavka.tel"
                },
                {
                    "label": "ВУЗ",
                    "name": "modx_vkrzayavka.vuz"
                },
                {
                    "label": "\u0424\u043e\u0440\u043c\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f",
                    "name": "modx_vkrzayavka.formob"
                },
                {
                    "label": "\u041e\u0442\u043a\u0443\u0434\u0430 \u043f\u0440\u0438\u0448\u0451\u043b?",
                    "name": "modx_vkrzayavka.gofrom"
                },
                {
                    "label": "\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c",
                    "name": "modx_vkrzayavka.spec"
                },
          ..........................
            // this fields are used in modx_vkrklient row creating END
            ]
             
            
        } );
    
        var t_zayavka = $('#vkrzayavka').DataTable( {
            ajax: 'php/table.modx_vkrzayavka.php',
            columns: [
                {
                    "data": "modx_vkrzayavka.obr"
                },
                {
                    "data": "modx_vkrzayavka.fio"
                },
                {
                    "data": "modx_vkrzayavka.toemail"
                },
                {
                    "data": "modx_vkrzayavka.tel"
                },
                {
                    "data": "modx_vkrzayavka.vuz"
                },
                {
                    "data": "modx_vkrzayavka.formob"
                },
                {
                    "data": "modx_vkrzayavka.gofrom"
                },
                {
                    "data": "modx_vkrzayavka.spec"
                },
                {
                    "data": "modx_vkrzayavka.disc"
                },
                {
                    "data": "modx_vkrzayavka.prep"
                },
                {
                    "data": "modx_vkrvidzak.vidname"
                },
                {
                    "data": "modx_vkrvidzak.step1"
                },
                {
                    "data": "modx_vkrvidzak.step2"
                },
                {
                    "data": "modx_vkrvidzak.step3"
                },
                {
                    "data": "modx_vkrvidzak.step4"
                },
                {
                    "data": "modx_vkrvidzak.step5"
                },
                {
                    "data": "modx_vkrvidzak.step6"
                },
                {
                    "data": "modx_vkrvidzak.step7"
                },
                {
                    "data": "modx_vkrzayavka.temerab"
                },
                {
                    "data": "modx_vkrzayavka.predprab"
                },
                {
                    "data": "modx_vkrzayavka.istreb"
                },
                {
                    "data": "modx_vkrzayavka.otdat"
                },
                {
                    "data": "modx_vkrzayavka.gomonth"
                },
                {
                    "data": "modx_vkrzayavka.strcnt"
                },
                {
                    "data": "modx_vkrzayavka.isotch"
                },
                {
                    "data": "modx_vkrzayavka.isplan"
                },
                {
                    "data": "modx_vkrzayavka.sfera"
                }
            ],
            select: true,
            language: 
    { ......
    },
            lengthChange: false
        } );
    
    
        new $.fn.dataTable.Buttons( t_zayavka, [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor },
            {
                text: "Обработать заказы",
                action: function ( e, dt, node, conf ) {
                    // Find indexes of rows which have '*' in the first column - obr
                    var indexes = t_zayavka.rows().eq( 0 ).filter( function (rowIdx) {
                        return t_zayavka.cell( rowIdx, 0 ).data() === '*' ? true : false;
                    } );
                    savdat=t_zayavka.rows( indexes ).data();
                    for (indzak = 0; indzak < savdat.length; indzak++) {
                        
                        /*1. Write part of row data to another table */ 
    
                            t_klient.row.add([
                            savdat[indzak]['modx_vkrzayavka']['fio'],
                            savdat[indzak]['modx_vkrzayavka']['toemail'],
                            savdat[indzak]['modx_vkrzayavka']['login'],
                            savdat[indzak]['modx_vkrzayavka']['pass'],
                            savdat[indzak]['modx_vkrzayavka']['tel'],
                            savdat[indzak]['modx_vkrzayavka']['vuz'],
                            savdat[indzak]['modx_vkrzayavka']['formob'],
                            savdat[indzak]['modx_vkrzayavka']['gofrom']
                        ]).draw(false);
                    }
    
                    alert("Rows created.");
                }
            }
        ] );
    
    $('#vkrzayavka_wrapper').on('click', 'a.buttons-edit', function(e)
     {
        e.preventDefault();
         
    editor.buttons( [
        {
            label: 'Обновить',
            className: 'primary',
            fn: function () {
                this.submit();
            }
        },
        {
            label: 'Создать заказ',
            fn: function () {
                this.field( 'modx_vkrzayavka.obr').set( '*' );
                this.message( 'Заказ поставлен в очередь. Не забудьте нажать "Обработать заказы", когда отметите все заявки.' );
                this.submit();
                }
        },
        {
            label: 'Снять заказ',
            fn: function () {
                this.field( 'modx_vkrzayavka.obr').set( ' ' );
                this.submit();
                alert( 'Заказ убран из очереди.' );
            }
        },
        {
            label: 'Закрыть',
            fn: function () {
                this.close();
            }
        }
    ] );
    }
    ); 
    
        t_zayavka.buttons().container()
        .appendTo( $('.col-sm-6:eq(0)', t_zayavka.table().container() ) );
    } );
    
  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Main question in this case is how declare modx_vkrklient table right way?
    It's declared in table.modx_vkrklient.js, as generated online.
    If I don't move declaration to table.modx_vkrzayavka.js, than t_klient variable not defined.
    If I declare it in action: function ( e, dt, node, conf )
    as

    var t_klient = $('#modx_vkrklient').DataTable();
    

    than I get error
    DataTables warning: table id=modx_vkrklient - Requested unknown parameter 'modx_vkrklient.fio' for row 5. For more information about this error, please see http://datatables.net/tn/4

    But modx_vkrklient.fio field is used in table.modx_vkrklien.js and table.modx_vkrklien.php in modx_vkrklient table declarations.

    If i use standart CRUD interface, all work properly.

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    I post direct links to all scripts I told about:

    http://uchet.nuzenavtor.ru/dt/vkr-admin.html
    http://uchet.nuzenavtor.ru/dt/js/table.modx_vkrzayavka.js
    http://uchet.nuzenavtor.ru/dt/js/table.modx_vkrzakaz_sm.js
    http://uchet.nuzenavtor.ru/dt/js/table.modx_vkrklient.js
    http://uchet.nuzenavtor.ru/dt/php/table.modx_vkrklient.php
    http://uchet.nuzenavtor.ru/dt/php/table.modx_vkrzayavka.php
    
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    If I've understood correctly, this block is causing the error:

                        t_klient.row.add([
                            savdat[indzak]['modx_vkrzayavka']['fio'],
                            savdat[indzak]['modx_vkrzayavka']['toemail'],
                            savdat[indzak]['modx_vkrzayavka']['login'],
                            savdat[indzak]['modx_vkrzayavka']['pass'],
                            savdat[indzak]['modx_vkrzayavka']['tel'],
                            savdat[indzak]['modx_vkrzayavka']['vuz'],
                            savdat[indzak]['modx_vkrzayavka']['formob'],
                            savdat[indzak]['modx_vkrzayavka']['gofrom']
                        ]
    

    Specifically, that code is adding an array to the table for the row. However, that table has been configured to expect an object.

    You want to add an object that matches the format of the data that is used to load the table's data on initialisation. For example (I'm not sure if I've selected the correct table here!):

            {
                "DT_RowId": "row_1",
                "modx_vkrklient": {
                    "fio": "Тапкин Майк",
                    "toemail": "I_mike@at.ru",
                    "login": "ataka",
                    "pass": "1324",
                    "tel": "",
                    "vuz": "АГУ",
                    "formob": "",
                    "spec": "",
                    "socseti": "",
                    "dopinf": "",
                    "city": ""
                }
            },
    

    Allan

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Actually - this might be the format needed for that table:


    { "DT_RowId": "row_39", "modx_vkrzayavka": { "obr": "", "fio": "Заморокин Сергей Иванович", "toemail": "ziborovvg@ya.ru", "tel": "+79396784500", "vuz": "АГУ", "formob": "Дневная", "gofrom": "В контакте", "spec": "Финансы", "disc": "Финансы", "prep": "Иванов", "typerab": "1", "is_step1": "1", "is_step2": "0", "is_step3": "0", "is_step4": "0", "is_step5": "0", "is_step6": "0", "is_step7": "0", "temerab": "Аудит торговой организации", "predprab": "667888,джлщлщл,ддзззх 34", "istreb": "1", "otdat": "2015-10-06", "gomonth": "3", "strcnt": "123", "isotch": "1", "isplan": "1", "sfera": "длололд" }, "modx_vkrvidzak": { "vidname": "Магистерская", "step1": "Получение методички", "step2": "Составление плана или его получение", "step3": "Введение и 1я глава и список литературы и приложения", "step4": "2 глава и приложения с отчетностью", "step5": "3 глава и заключение и приложения", "step6": "Общее оформление", "step7": "Оригинальность" } },

    Allan

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Hi.
    Thank you for a detailed analysis of my code , Allan

    It's very undesirable for me to use an array data format instead of an object, so I try
    to convert problem block of code to object format.

    /*1. Write part of row data to another table            */
     t_kli.row.add({
            'fio'    :  savdat[indzak]['modx_vkrzayavka']['fio'],
            'toemail':  savdat[indzak]['modx_vkrzayavka']['toemail'],
            'login'  :  savdat[indzak]['modx_vkrzayavka']['login'],
            'pass'   :  savdat[indzak]['modx_vkrzayavka']['pass'],
            'tel'    :  savdat[indzak]['modx_vkrzayavka']['tel'],
            'vuz'    :  savdat[indzak]['modx_vkrzayavka']['vuz'],
                    'formob' :  savdat[indzak]['modx_vkrzayavka']['formob'],
                    'spec'   :  savdat[indzak]['modx_vkrzayavka']['spec'],
            'socseti':  savdat[indzak]['modx_vkrzayavka']['gofrom'],
            'dopinf' :  '',
            'city'   :  ''    
     }).draw(false);
    

    But I do something wrong and error again:
    DataTables warning: table id=modx_vkrklient - Requested unknown parameter 'modx_vkrklient.fio' for row 5. For more information about this error, please see http://datatables.net/tn/4
    If I use aliases with field names, it's change nothing.
    How must I convert this code block for proper object format getting?

    But... Sorry. I do it more clear now. This code not in object format yet.

    And write result after.

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    I'd redo this code. But very less better...

    t_kli.row.add({
            "modx_vkrklient": {
    'fio'    :  savdat[indzak]['modx_vkrzayavka']['fio'],
    'toemail':  savdat[indzak]['modx_vkrzayavka']['toemail'],
    'login'  :  savdat[indzak]['modx_vkrzayavka']['login'],
    'pass'   :  savdat[indzak]['modx_vkrzayavka']['pass'],
    'tel'       :  savdat[indzak]['modx_vkrzayavka']['tel'],
    'vuz'    :  savdat[indzak]['modx_vkrzayavka']['vuz'],
    'formob' :  savdat[indzak]['modx_vkrzayavka']['formob'],
    'spec'   :  savdat[indzak]['modx_vkrzayavka']['spec'],
    'socseti':  savdat[indzak]['modx_vkrzayavka']['gofrom'],
    'dopinf' :  '',
    'city'   :  ''  }
        }).draw(false);
    

    I get message

    DataTables warning: table id=modx_vkrklient - Requested unknown parameter "modx_vkrklient.login" for row 9. For more information about this error, please see http://datatables.net/tn/4

    I can't clearly interpret it . Perhaps the problem is strictly observed object format. But I not clear understand it yet.
    Very strange is that message

    unknown parameter 'modx_vkrklient.login'

    modx_vkrklient.login is the third field, but what about the first two...

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Strange problem with variable scope.
    Than I work with table modx_vkrzayavka this code work fine.

    var t_zayavka = $('#vkrzayavka').DataTable( {
            ajax: 'php/table.modx_vkrzayavka.php'
    . . . 
    });
    new $.fn.dataTable.Buttons( t_zayavka, [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor },
            {
                text: "Save data",
                action: function ( e, dt, node, conf ) {
                    // Find indexes of rows which have `Yes` in the second column
                    var indexes = t_zayavka.rows().eq( 0 ).filter( function (rowIdx) {
                        return t_zayavka.cell( rowIdx, 0 ).data() === '*' ? true : false;
                    } );
    
                    savdat=t_zayavka.rows( indexes ).data();
                    alert("Data saved.");
                }
        }
        ] );
    

    But with other table - modx_vkrklient, I can't save data.
    The similar code generate error " t_klient is not defined".

    var t_klient = $('#modx_vkrklient').DataTable( {
            dom: 'Bfrtip',
            ajax: 'php/table.modx_vkrklient.php',
        ....
        } );
    } );
    
    new $.fn.dataTable.Buttons( t_klient, [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor },
            {
                text: "Save data",
                action: function ( e, dt, node, conf ) {
                    savkli=t_klient.rows().data();
                    alert("Data saved.");
                }
            }
        ] );
    

    I want only save table data to see real object structure.(((

    Than I try use t_klient or t_zayavka in Console of Firebug, I always get the message "Variable not defined".

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Is Datable Debug show real table object structure?
    http://debug.datatables.net/apoqed
    If yes, I find _aData var and see that real structure is:
    "_aData": { "DT_RowId": "row_4", "modx_vkrklient": { "fio": "Васькин Петя", "toemail": "vas@vas.ru", "login": "garet", "pass": "4656", "tel": "", "vuz": "", "formob": "", "spec": "", "socseti": "", "dopinf": "", "city": "" } }

    I tried to use it today, but did not set the correct option DT_RowId.
    How can set it with right way?

    p.s. code format is dropped again. I try correct it three times, but I can't. Sorry

    pps.
    I have found discussion about DT_RowId https://datatables.net/forums/discussion/26133/get-dt-rowid-before-calling-process-post
    there you write:

    On edit you can get the id that is being used with $_POST['id'] (see the client / server
    communication docs). However, on create, obviously the id won't exist until the row has
    actually been created (which is done by process()).

    If so, must I really set it?

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    When I tried to set object value directly , it worked perfectly .

    t_kli.row.add({
        "modx_vkrklient": {
                         'fio'    :  'Иванов ИИ',
                         'toemail':  'to@to.ru',
                         'login'  :  'BosS',
                         'pass'   :  '122678',
                         'tel'    :  '989786454',
                         'vuz'    :  'FAdd',
                         'formob' :  'Очная',
                         'spec'   :  'Эко',
                         'socseti':  'ВК',
                         'dopinf' :  '',
                         'city'   :  ''
            }
          }).draw(false);
    

    ~~So, the last question is how convert field set to object? Is it possible to use a function as object source?~~

    ~~I try to construct code above with $.globalEval():~~

    ~~$.globalEval("t_kli.row.add(cur_obj).draw(false);");~~
    
    

    ~~ but it don`t working and generate error~~

    ~~ReferenceError: t_kli is not defined~~

    It's all was pointless, because the added record is not saved.

    the next attempt to do the same with Editor`s API.

    P.S. Strikethrough in Markdown is not supported here?

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    The next attempt:
    I add one more instance of Editor with:
    ```
    var e_copy = new $.fn.dataTable.Editor( {
    ajax: 'php/table.modx_vkrklient.php',
    table: '#modx_vkrklient',
    fields: [
    {
    "label": "\u0424\u0418\u041e",
    "name": "modx_vkrklient.fio"
    },
    {
    "label": "E-mail",
    "name": "modx_vkrklient.toemail"
    },
    {
    "label": "\u041b\u043e\u0433\u0438\u043d",
    "name": "modx_vkrklient.login"
    },
    {
    "label": "\u041f\u0430\u0440\u043e\u043b\u044c",
    "name": "modx_vkrklient.pass"
    },
    {
    "label": "\u0422\u0435\u043b\u0435\u0444\u043e\u043d",
    "name": "modx_vkrklient.tel"
    },
    {
    "label": "\u0412\u0423\u0417",
    "name": "modx_vkrklient.vuz"
    },
    {
    "label": "\u0424\u043e\u0440\u043c\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f",
    "name": "modx_vkrklient.formob"
    },
    {
    "label": "\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c",
    "name": "modx_vkrklient.spec"
    },
    {
    "label": "\u0421\u043e\u0446\u0441\u0435\u0442\u0438",
    "name": "modx_vkrklient.socseti"
    },
    {
    "label": "\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f",
    "name": "modx_vkrklient.dopinf"
    },
    {
    "label": "\u0413\u043e\u0440\u043e\u0434",
    "name": "modx_vkrklient.city"
    }
    ]
    } );

    ```
    p.s. code format is dropped again. Sorry

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    and rewrite my code:

     {
                        /*1. Write part of row data to another table*/
                        e_copy
                            .create( false )
                            .set( {
                            fio: 'Test user',
                            toemail : 'to@email.ru',
                            login  :  'BosS',
                            pass   :  '122678',
                            tel    :  '989786454',
                            vuz    :  'FAdd',
                            formob :  'Очная',
                            spec   :  'Эко',
                            socseti:  'ВК',
                            dopinf :  '',
                            city   :  ''
                            } )
                            .submit();
    
                    }
    
                    alert("Row created.");
                }
    

    but I get error:

    TypeError: c[a] is undefined dataTables.editor.min.js:51:228

    Update:
    I found it)))

    If no element with a matching data-editor-id attribute is found no action is taken. You would need to use postCreate to insert the newly created item into the display.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    This one looks the closest to what you want I think:

    t_kli.row.add({
      "modx_vkrklient": {
        'fio': savdat[indzak]['modx_vkrzayavka']['fio'],
        'toemail': savdat[indzak]['modx_vkrzayavka']['toemail'],
        'login': savdat[indzak]['modx_vkrzayavka']['login'],
        'pass': savdat[indzak]['modx_vkrzayavka']['pass'],
        'tel': savdat[indzak]['modx_vkrzayavka']['tel'],
        'vuz': savdat[indzak]['modx_vkrzayavka']['vuz'],
        'formob': savdat[indzak]['modx_vkrzayavka']['formob'],
        'spec': savdat[indzak]['modx_vkrzayavka']['spec'],
        'socseti': savdat[indzak]['modx_vkrzayavka']['gofrom'],
        'dopinf': '',
        'city': ''
      }
    }).draw(false);
    

    If fio and toemail work, it suggests that either they aren't being used in the table, or perhaps login is shown first. The other option is that savdat[indzak]['modx_vkrzayavka']['login'] might be null or undefined.

    If you do:

    console.log( JSON.stringify( savdat ) );
    

    immediately before the t_kli.row.add - what do you see?

    I'm actually wondering if it is going to be easier for you to simply reload the target table - use t_kli.ajax.reload(). That will get the data for the table from the server - and it will include the row id (which is important if you want to be able to edit it!). It does mean that more data is transmitted, but I suspect you'll find it a lot easier to actually use (I know I would!).

    Regards,
    Allan

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    If you do:
    console.log( JSON.stringify( savdat ) );
    immediately before the t_kli.row.add - what do you see?

    I see error message: TypeError: cyclic object value

    If I look at savdat in Console, I see:

    Object { 0: Object, 1: Object, 2: Object, 3: Object, context: Array[1], length: 4, selector: Object, tables: S/t.extend/g/<(), table: S/t.extend/g/<(), draw: S/t.extend/g/<(), more 27 … }

    And first 3 objects are:

    0 - {DT_RowId:"row_36",
           modx_vkrvidzak:Object,
          modx_vkrzayavka:Object,
          __proto__:Object}
    1 - {DT_RowId:"row_35",
           modx_vkrvidzak:Object,
          modx_vkrzayavka:Object,
          __proto__:Object}
    2 - {DT_RowId:"row_53",
           modx_vkrvidzak:Object,
          modx_vkrzayavka:Object,
          __proto__:Object}
    
    

    Three rows with joined data.

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    If you go back to the end of my previous posts, the main question that remained unanswered - will the saved records added in this way, using Datatables API?
    Am I right in thinking further using Editor`s API?

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    If the PHP uses a join that provides access to all three tables (i.e. uses a leftJoin) then yes, it can write to all three tables. It is obviously a lot more difficult for the code to do that, and you must be sure to include the primary key field for all of the tables in the source data and in the data you send back to the server. Generally I would recommend that you write only to a single table at a time when using Editor.

    Allan

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Yes, I understand now, it's easier to do it with a separate PHP script with PDO.

    Thank you.

    Vitaliy.

This discussion has been closed.