Read-only columns displayed only in DataTable?

Read-only columns displayed only in DataTable?

burncharburnchar Posts: 118Questions: 12Answers: 0
edited October 2012 in Editor
The following example in the always impressive documentation describes how to hide certain columns from only the Editor view:
http://editor.datatables.net/release/DataTables/extras/Editor/examples/tableOnlyData.html

This seems to be meant for server-generated fields, like the example's "Last updated."

I have a table (a view, actually) with numerous information-only columns that cannot be edited.
Is there another way to make these columns invisible to the editor?

The problem is that, using the example, I'd have to send the row ID as a custom entry in the edit request then re-query the server for the columns in that row and manually combine them before generating "row" in the JSON. The DataTable already has those values, so it seems like there must be an easier way than the complex and slow one I thought of.

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    > Is there another way to make these columns invisible to the editor?

    Can you not just remove them from the Editor initialisation?

    With Editor 1.2 you can return the data object for the row (as the `row` object) and DataTables will update the whole row. If you are using the Editor 1.2 PHP classes, it will do all of this for you.

    Allan
  • burncharburnchar Posts: 118Questions: 12Answers: 0
    If I remove them from Editor initialization, Editor complains about missing values on submit. Am I doing this wrong?

    I'm using .NET so can't use the classes.
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Does Editor complain, or is it the server-side script which is expecting them and thus complaining? What I would expect the setup to look like is:

    [quote]
    Editor init
    - field 1
    - field 2
    - field 3 [...]

    DataTables init
    - field 1
    - field 2
    - field 3
    - field 4
    - field 5 [...]
    [/quote]

    So Editor is only submitting three fields, but you have 5 in the DataTable. Then the server can reply with 'row' providing the full data object for the edited row, which Editor will pass on to the DataTable ( see the 'A a new record' JSON submit / return example here: http://editor.datatables.net/server/ ).

    Allan
  • burncharburnchar Posts: 118Questions: 12Answers: 0
    I'm relieved it's supposed to work that way, but I must be doing something wrong. Is it because I am using aoColumns which the docs say, "the length of this array must be equal to the number of columns in the original HTML table."? The original table really does have the "RECIPE_NOTES" column, though.

    When I use sDefaultContent, no error occurs but the column's value after edit is replaced by the default content every time.

    What am I screwing up?

    I get the following error: http://imgur.com/zPF5w
    [code]
    // Editor init
    "fields": [
    { "label": "Device:", "name": "DEVICE" },
    { "label": "ROM:", "name": "ROM" },
    { "label": "ECA:", "name": "ECA" },
    { "label": "Process:", "name": "PROCESS" },
    { "label": "Stage:", "name": "STAGE" },
    { "label": "Parent order:", "name": "PARENT_ORDER" },
    { "label": "Child order:", "name": "CHILD_ORDER" },
    { "label": "Dose:", "name": "DOSE" },
    { "label": "Recipe:", "name": "RECIPE" },
    { "label": "Parent recipe:", "name": "PARENT_RECIPE" },
    { "label": "AMU:", "name": "SPECIES_AMU" },
    { "label": "Chemical formula:", "name": "SPECIES_CHEMICAL_FORMULA" },
    { "label": "Energy:", "name": "ENERGY" },
    { "label": "Tilt:", "name": "TILT" },
    { "label": "Twist:", "name": "TWIST" },
    { "label": "Rotation:", "name": "ROTATION" },
    { "label": "Equipment:", "name": "EQUIPMENT[].id", "type": "checkbox" }
    //{ "label": "Notes:", "name": "RECIPE_NOTES" }
    ],
    [/code]

    [code]
    // DataTables init
    "aoColumns": [
    {"mData":"DEVICE"},
    {"mData":"ROM"},
    {"mData":"ECA"},
    {"mData":"PROCESS"},
    {"mData":"STAGE"},
    {
    // Show the order with child recipes as "X.Y", or just "X" without.
    "mData":"PARENT_ORDER",
    "mRender": function (data, type, row) {
    var retval = row['PARENT_ORDER'];
    if(row['CHILD_ORDER'] != null && row['CHILD_ORDER'].length > 0) retval += "." + row['CHILD_ORDER'];
    return parseFloat(retval);
    }
    },
    {
    // Show DOSE as an exponent rather than a very long integer.
    "mData":"DOSE",
    "mRender": function (data, type, row) {
    return(parseFloat(data).toExponential(2));
    }
    },
    {"mData":"RECIPE"},
    {"mData":"PARENT_RECIPE"},
    {"mData":"SPECIES_AMU"},
    {"mData":"SPECIES_CHEMICAL_FORMULA"},
    {"mData":"ENERGY"},
    {"mData":"TILT"},
    {"mData":"TWIST"},
    {"mData":"ROTATION"},
    {
    "mData":"EQUIPMENT",
    "mRender":"[, ].name"
    },
    {"mData":"RECIPE_NOTES"}
    ],
    [/code]
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    > "the length of this array must be equal to the number of columns in the original HTML table."

    Yes that is correct - but I think you might be forgetting about the extra dimension of the data source object. If you are Ajax loading the data, then your data source objects do not have to match the HTML at all (obviously you'd typically one one property for each column, but that's not always true :-) ) - the mData option provides DataTables with the mapping information to get the data from the object into the columns.

    So yes, the aoColumns length must match the number of columns in the HTML source - but no, the data source object does not also need to meet that requirement.

    The thing to keep in mind here is that you are passing the data source object in - if you were to use DOM sourced data, then DataTables creates the data source object, based upon the data read from the document (at which point it can only be that the data source object is exactly the same length as the data read!).

    Heh - a bit confusing, I hope I've not just made it even muddier!

    Allan
This discussion has been closed.