How divide current row of one table between the two other tables
How divide current row of one table between the two other tables
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
Make simple live test - try to add one row in table. Don`t working at all(.
http://live.datatables.net/qiqizeka/1/
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.
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
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.
The main subtlety was that using
t.row().add
, as I tried before, don't working)))).I tried to format code example, as you recommend,
I edit it four times,but it collapsed every time(((
Don`t understand why...
But in fifth time all is Ok.
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.
Main part of index.html:
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.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
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 intable.modx_vkrklien.js
andtable.modx_vkrklien.php
in modx_vkrklient table declarations.If i use standart CRUD interface, all work properly.
I post direct links to all scripts I told about:
If I've understood correctly, this block is causing the error:
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!):
Allan
Actually - this might be the format needed for that table:
Allan
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 anobject
, so I tryto convert problem block of code to
object
format.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?And write result after.
I'd redo this code. But very less better...
I get message
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
modx_vkrklient.login
is the third field, but what about the first two...Strange problem with variable scope.
Than I work with table modx_vkrzayavka this code work fine.
But with other table - modx_vkrklient, I can't save data.
The similar code generate error " t_klient is not defined".
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".
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-postthere you write:
If so, must I really set it?
When I tried to set object value directly , it worked perfectly .
~~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():~~
~~ but it don`t working and generate error~~
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?
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
and rewrite my code:
but I get error:
Update:
I found it)))
This one looks the closest to what you want I think:
If
fio
andtoemail
work, it suggests that either they aren't being used in the table, or perhapslogin
is shown first. The other option is thatsavdat[indzak]['modx_vkrzayavka']['login']
might be null or undefined.If you do:
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
I see error message: TypeError: cyclic object value
If I look at
savdat
in Console, I see:And first 3 objects are:
Three rows with joined data.
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?
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
Yes, I understand now, it's easier to do it with a separate PHP script with PDO.
Thank you.
Vitaliy.