Updating a table field after editing.

Updating a table field after editing.

IlyasIlyas Posts: 3Questions: 0Answers: 0
edited June 2013 in Editor
Hi
In a table in my database I store some key-value pairs.
When my dataTable is being rendered I show only the value.

[code]
oTable = $('#tbl').dataTable({
"aoColumns": [
{ "mData": "Mod" }
{ "mData": "Other" }
],
[/code]

but the server returns both "ModId" (the key) and "Mod" (the value) and the "other" data

On editing, the field is a "select" which is initialized by that key-value table from db. It is initialized as needed, so the selected value is exactly the same as shown in the dataTable, because initialization is by that key, passed before.

[code]
$(document).ready(function () {
editor = new $.fn.dataTable.Editor({
"ajaxUrl": "Data.aspx",
"domTable": "#tbl",
"fields": [
{ "label": "Mod", "name": "ModId", "type": "select", "ipOpts": getModList() },
{ "label": "other", "name": "Other" },
]
});
[/code]

After clicking "update" in the editor I have the following error
"DataTables warning tableId='tbl' requested unknown parameter 'Mod' from the dataSource for row 5"

And, as rendered, the 'Mod' value turns empty. Though the data is updated and after a refresh I have the new value shown.

Please help me solve the issue.
How can i connect between the value selected in the editor and the new value shown in dataTable right after updating?

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,051 Site admin
    Hi,

    Are you able to link us to the page you are working on so we can look at it directly and resolve the issue?

    Also, I don't have a record of an Editor license for your account, either a trial or purchased license. Could you tell me how you are using Editor so I can update my records and provide the appropriate level of support.

    Regards,
    Allan
  • IlyasIlyas Posts: 3Questions: 0Answers: 0
    edited June 2013
    Foa, thanks for the quick response.

    Secondly, I'm working on an editor provided by my superior. So my account is not linked to whatever license or trial it has (I think its trial though).

    It's very problematic for me to link you to the page because, it's intranet app.

    I can provide other code details if you need, and here is debugger output (preedit)
    http://debug.datatables.net/anisah

    Also here is the stored procedure which returns the data as I said before.

    [code]
    select
    t1.Value as Mod,
    t1.Id as ModId,
    t2.Other
    From t1 inner join t2 on t1.Id = t2.ModId
    ORDER BY t2.Other
    [/code]

    I also wanted to create a postedit output but something seems to go wrong there, and the debugger doesn't work, it stops at:

    [quote]DataTables debug bookmarklet
    Creating debug information...[/quote]

    Thank you in advance...
  • IlyasIlyas Posts: 3Questions: 0Answers: 0
    edited June 2013
    Came up with the solution, added onPreEdit event to editor initialization, where i put the needed value by the edited key.

    [code]

    $(document).ready(function () {
    editor = new $.fn.dataTable.Editor({
    "ajaxUrl": "Data.aspx",
    "domTable": "#tbl",
    "events": {
    "onPreEdit": function (json, data) {
    data.Mod = getEnumValueById(data.ModId);
    }
    },
    "fields": [
    { "label": "Mod", "name": "ModId", "type": "select", "ipOpts": getModList() },
    { "label": "other", "name": "Other" },
    ]
    });

    oTable = $('#tbl').dataTable({
    "aoColumns": [
    { "mData": "Mod" }
    { "mData": "Other" }
    ],

    [/code]

    But now as I come back from the editor my whole table changes it's alignment. Almost all columns width are changed even after I add "sWidth" I suppose it's because of the 'smart' width.

    How can i turn that "'smart' width" down?
  • allanallan Posts: 61,438Questions: 1Answers: 10,051 Site admin
    You can use bAutoWidth to disable the 'smart width' calculations. It would be interesting to know if that helps.

    Thanks,
    Allan
This discussion has been closed.