Editor: One-to-many join with multiple inputs

Editor: One-to-many join with multiple inputs

htwyfordhtwyford Posts: 23Questions: 9Answers: 1
edited June 2017 in Free community support

I am performing a one-to-many join with the .NET library, then displaying the results in an Editor table. The joined data is joining multiple numeric budget values to one job. I'd like for the table to display the list of jobs, with all of the budget values editable. The MJoin example gives the example of checkboxes, but I haven't found an example of an MJoin with multiple text/number inputs. Has anyone found a way to implement this? My .NET code:

var editor = new Editor(dtDb, "Job", "ID")
    .Model<JobIndexViewModel>()
    .Where("parentJobID", null);
    .MJoin (new MJoin("Budget")
        .Link("Job.ID", "Budget.JobID")
        .Model<BudgetLinkViewModel>());
var response = editor.Process(Request.Form)
                        .Data();

return Json(response, JsonRequestBehavior.AllowGet);

and part of my DataTable/Editor JS code

var editor;
$(document).ready(function () {
    //// **** EDITOR INITIALIZATION **** ////
    editor = new $.fn.dataTable.Editor({
        ajax: {
            url: ajaxUrl
        },
        table: '#job_index',
        fields: [
            {
                label: "Budgets:",
                name: "Budget[].amount_remaining",
            }
        ]
    });

    //// **** DATATABLES INITIALIZATION **** ////
    var table = $('#job_index').DataTable({
        dom: "Bfrtip",
        ajax: {
            url: ajaxUrl
        },
        columns: [
            {
                data: "Job.job_number"
            },
            {
                data: "Job.job_name"
            },
                ...
            { data: "Budget", render: "[, ].amount_remaining" }
        ],
        select: true,
        lengthChange: true,
        buttons: [
            ...
        ]
    });
});

Right now the Editor form just gives me a single textbox with comma-separated number values, which is not ideal. I'd prefer it look something like

-----------------------------------
Custom Budget Name 1      ||  400
-----------------------------------
Custom Budget Name 2      ||  500
-----------------------------------
Custom Budget Name 3      ||  350

EDIT: The custom budget names are passed in the Json, but I know we can't define field/column names in Json. It's OK if I have to hardcode those.

EDIT 2: Something like this example but where I don't know exactly how many budgets will be in the bubble.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Answer ✓

    I haven't found an example of an MJoin with multiple text/number inputs. Has anyone found a way to implement this?

    As in you want to be able to add / edit / delete data from the Mjoin inside the Editor form?

    I'm afraid that this is not a feature of Editor at this time - it is something that I'm going to be adding in future.

    At the moment it would be possible to create a custom field type which would add / edit / delete a single datapoint - when you are editing a table with multiple columns, then its a bit more difficult since it needs to consider information that isn't visible.

    Sorry this isn't something that is directly available at the moment. Typically you would need to redirect to another DataTable / Editor page that allows editing of that table.

    Allan

  • advaniaadvania Posts: 35Questions: 13Answers: 0

    I have the same request, in my case, i have a file that the user uploaded, and each file has multiple sub-fields in a seperate table which need to be editable but are also mandatory.

    Too bad it is not directly supported.

  • ypMUw5X45nOkypMUw5X45nOk Posts: 2Questions: 0Answers: 0

    @allan, I'm interested in this feature as well.

  • ypMUw5X45nOkypMUw5X45nOk Posts: 2Questions: 0Answers: 0

    This article helped me find a decent solution: https://datatables.net/blog/2016-03-25

This discussion has been closed.