Hide field in table and form

Hide field in table and form

paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

Hi,

I need some fields from a table to caculate KPIs and show them as fieldInfo, but I don't want to show the fields in the table and in the forms as well.

I only find this both examples "Data shown only in the form" and "Data shown in table only" where you can hide it in the form or the table.

Is the an atribute ála readonly or hide for form fields?

Thanks for any support

Cheers Patrick

This question has an accepted answers - jump to answer

Answers

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0
  • ApezdrApezdr Posts: 43Questions: 4Answers: 5
    Answer ✓

    Howdy,

    If you want to omit fields from showing in the Editor you can simply omit it from the editor instancing.

    Example.

    var table = $('#ClientData').DataTable( {
            ajax: ajaxURL,
            columns: [
                {
                    "title":"Client Name",
                    "data": "ClientData.ClientName"
                },
                {
                    "title": "Rev Projection:",
                    "data": "ClientData.RevProjection",
                    "render": $.fn.dataTable.render.number( ',', '.', 0, '$' )
                }
    
    var editor = new $.fn.dataTable.Editor( {
            ajax: ajaxURL,
            table: '#ClientData',
            fields: [
                {
                    "label": "Client Name:",
                    "name": "ClientData.ClientName"
                }
    

    If you don't define it in the editor instance it wont load the field in the editor form.

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    Oh I see and I will try this solution as well.

    Thank you very much man

    Cheers Patrick

  • bpernikoffbpernikoff Posts: 4Questions: 1Answers: 0

    I tried this solution of omitting the field from the editor fields: definition and received the following error:

    dataTables.editor.js:2771 Uncaught Unknown field name - itemSize

    I'm looking for the same solution - to display the column but hide it from the edit form. Thanks in advance.

  • colincolin Posts: 15,238Questions: 1Answers: 2,599

    Hi bpernikoff,

    The most likely cause, without seeing your code, is that the field itemSize really doesn't exist - is it a typo, or has it been removed?

    If that's not the cause, please post your code and we can take a look. It might be best to do it in a new forum thread and just link to this one.

    Cheers,

    Colin

  • bpernikoffbpernikoff Posts: 4Questions: 1Answers: 0

    Hi Colin,

    Thanks for replying. Here is my code which is only using the in memory table to be used to post the data back to an endpoint.

    The table definition: itemSize is a hidden column used as a placeholder so the total for all file sizes can be calculated.


    $('#savedItemsTable').DataTable({ dom: "Bfrtip", data: $.map(todo, function (value, key) { return value; }), columns: [ { data: "itemID"}, { data: "itemLocation" }, { data: "itemCustodian", className: 'editable' }, { data: "itemEvidenceID", className:'editable' }, { data: "itemSize", visible:false } ], select: { style: 'os', selector: 'td:first-child', blurable: true }, buttons: [ //{ extend: "create", editor: editor } { extend: "edit", editor: editor }, { extend: "remove", editor: editor } ] });

    Here is the Editor: I was hoping to omit the itemSize from the fields as per your instruction so that it does not appear on the edit form but doing so throws that error (dataTables.editor.js:2771 Uncaught Unknown field name - itemSize)

           var editor = new $.fn.dataTable.Editor({
                table: '#savedItemsTable',
                fields: [{ label: "Item Id", name: "itemID" },
                         { label: "Title", name: "itemLocation" },
                         {
                             label: "Custodian", name: "itemCustodian", type: "select",
                             options: [
                                 { label: "Mary Goodman", value: "Marty Goodman" },
                                 { label: "John Lewis", value: "John Lewis" },
                                 { label: "Howard Jones", value: "Howard Jones" }
                             ] },
                         { label: "Evidence Id", name: "itemEvidenceID" },
                         { label: "File Size", name: "itemSize", visible: false }],
    
                ajax: function (method, url, d, successCallback, errorCallback) {
                    var output = { data: [] };
    
                    if (d.action === 'create') {
                        // Create new row(s), using the current time and loop index as the row id
                        var dateKey = +new Date();
    
                        $.each(d.data, function (key, value) {
                            var id = dateKey + '' + key;
                            value.DT_RowId = id;
                            todo[id] = value;
                            output.data.push(value);
                        });
                    }
                    else if (d.action === 'edit') {
                        // Update each edited item with the data submitted
                        $.each(d.data, function (id, value) {
                            value.DT_RowId = id;
                            $.extend(todo[id], value);
                            output.data.push(todo[id]);
                        });
                    }
                    else if (d.action === 'remove') {
                        // Remove items from the object
                        $.each(d.data, function (id) {
                            delete todo[id];
                        });
                        ///... update the file size total here
                    }
                    // Show Editor what has changed
                    successCallback(output);
                }
            });
    
  • colincolin Posts: 15,238Questions: 1Answers: 2,599

    Hi again,

    Please take a look at second comment in this thread, it points to this page. If you add the hidden then that'll sort you out.

    Cheers,

    Colin

This discussion has been closed.