How to pass Master RecID?

How to pass Master RecID?

ITDATAGITDATAG Posts: 18Questions: 6Answers: 1

Hello I am still looking to get the hang of Editor and Datatables I am trying to set up a master- details view of which seems to work to some extend. The issue is when I try to add a detail record I am not able to pass the master Rec id for the link. I looked at join tables but I am a bit confused.

Provide a bit of guidance.
see the pictures
Masters record (picture MasterRecord) Provides the sumary of the Table with an Activity Button.

When click the activity Button open "Editor" create screen see (Details Pic).

I enter the information and it doesnt give an error but it doesn't save. The code for my server side code is the following:

public ActionResult ActRec()
{

        // DtRequest request = HttpContext.Request;
        var settings = Properties.Settings.Default;

        using (var db = new Database(settings.DbType, settings.DbConnection))
        {
            var response = new Editor(db, "SaActivity", "ActID")
                .Model<saActRec>()
                .Field(new Field("ActivityType")
                    .Validator(Validation.NotEmpty())
                )
                  .Field(new Field("ActDate")
                    .Validator(Validation.DateFormat(
                        Format.DATE_ISO_8601,
                        new ValidationOpts { Message = "Please enter a date in the format yyyy-mm-dd" }
                    ))
                    .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601))
                    .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                )
                .Field(new Field("Contact")

                )
                .Field(new Field("Reference")
                    .Validator(Validation.NotEmpty())
                )
                .Field(new Field("Notes")

                )
                .Field(new Field("SalesOpId") 

                )
                .Process(Request.Form)
                .Data();

            return Json(response);
        }

//JQuery for the "Add Activity"
$('#MyTable').on('click', '#AddAct', function () {
var tr = $(this).closest('tr');
console.log(tr)
editor1
.buttons({
label: "Save",
fn: function () { this.submit(); }
})
.edit(tr);
});

Please help if you could point me in the right direction.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi,

    Have you seen this blog post on the topic of master / child editable tables?

    I enter the information and it doesnt give an error but it doesn't save

    Does it submit the data to the server via Ajax? (check the network tab in your browser's inspector).

    Allan

  • ITDATAGITDATAG Posts: 18Questions: 6Answers: 1

    Hello Alllan,

    This is what the network tab shows.


  • ITDATAGITDATAG Posts: 18Questions: 6Answers: 1

    Hello Allan,

    I reviewed the sample post, thanks for the suggestion it is exactly what I am trying.. However I am having a few issues that have my head spinning..

    1.) When I expand the child row.. I get a notification that two field are ambiguous even though I use the dot notation to specify their tables (See Pic).

    Here is the code as in the jquery:

    function createChild(row) {
    // This is the table we'll convert into a DataTable
    var table = $('

    '); // Display it the child row row.child(table).show(); var rowData = row.data(); // Editor definition for the child table var ActEditor = new $.fn.dataTable.Editor({ ajax: { url: "/CRM/ActRec", data: function (d) { d.SalesOpID = rowData.SalesOpId; } }, table: table, fields: [{ label: "ActivityType:", name: "ActivityType" }, { label: "Activity Date:", name: "ActDate", type: "datetime" }, { label: "Contact:", name: "Contact" }, { label: "Reference:", name: "Reference" }, { label: "Notes:", name: "saActivity.Notes" } ] }); // Initialise as a DataTable var ActTable = table.DataTable({ dom: "Bfrtip", pageLength: 5, ajax: { url: "/CRM/ActRec", type: "post", data: function (d) { d.SalesOpID = rowData.SalesOpId; } }, columns: [ { title: "ActivityType", data: "ActivityType" }, { title: "ActDate ", data: "ActDate" }, { title: "Contact", data: "Contact" }, { title: "Reference", data: "Reference" }, { title: "Notes", data: "saActivity.Notes" } ], select: true, buttons: [ { extend: "create", editor: ActEditor }, { extend: "edit", editor: ActEditor }, { extend: "remove", editor: ActEditor } ] }); and the code on the Controller: public ActionResult ActRec() { var request = HttpContext.Request; var settings = Properties.Settings.Default; var formData = HttpContext.Request.Form; using (var db = new Database(settings.DbType, settings.DbConnection)) { var response = new Editor(db, "SaActivity", "ActID") .Model<saActRec>() .Field(new Field("SaActivity.ActivityType") .Validator(Validation.NotEmpty()) ) .Field(new Field("SaActivity.ActDate") .Validator(Validation.DateFormat( Format.DATE_ISO_8601, new ValidationOpts { Message = "Please enter a date in the format yyyy-mm-dd" } )) .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601)) .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601)) ) .Field(new Field("SaActivity.Contact") ) .Field(new Field("SaActivity.Reference") .Validator(Validation.NotEmpty()) ) .Field(new Field("SaActivity.Notes") ) .Field(new Field("SaActivity.SalesOpId") ) .LeftJoin("saMainRec", "SaMainRec.SalesOpID", "=", "saActivity.SalesOpId") //.Where("saMainRec",Request.Form) .Process(Request.Form) .Data(); return Json(response); } Thanks for the help, any pointers or recommendation greatly appreciated
  • ITDATAGITDATAG Posts: 18Questions: 6Answers: 1

    Allan,

    Please disregard last Post.. I found the issue.

This discussion has been closed.