Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2048
CRUD operations on childs
posted

Hi,

I followed your media item "CRUD with JQuery Grid", and I applied it right to my example. It works all fine, but I have some problems when I try to implement CRUD operations also on child columns.

My javascript understands that a new child row has been added, or deleted or edited, but what my controller action receives is an empty transaction log.

Here is my code:

 

@(Html.Infragistics().Grid(Model)
.ID("grid1")
.UpdateUrl(Url.Action("UpdateData"))
.AutoCommit(false)
.AutoGenerateColumns(true)
.PrimaryKey("Id")
.Columns(col =>
{
    col.For(x => x.Id);
    col.For(x => x.Code);
    col.For(x => x.Description).HeaderText("Descrizione");
    col.For(x => x.Type).HeaderText("Tipologia");
})
.Width("100%")
.Features(feat =>
{
    feat.Updating()
        .StartEditTriggers(GridStartEditTriggers.DblClick)
        .ColumnSettings(colset =>
            {
                colset.ColumnSetting().ColumnKey("Id").Required(true);
                colset.ColumnSetting().ColumnKey("Code").Required(true);
                colset.ColumnSetting().ColumnKey("Description").Required(true);
                colset.ColumnSetting().ColumnKey("Type").EditorType(ColumnEditorType.Numeric).EditorOptions("groupSeparator: '', maxDecimals: 0 ").Required(true);
            });
})
.AutoGenerateLayouts(false)
.ColumnLayouts(layouts =>
{
    layouts.For(l => l.SubProducts)
    .AutoGenerateColumns(false)
    .ForeignKey("Id")
    .PrimaryKey("Id")
    .Columns(childcol =>
    {
        childcol.For(c => c.Id);
        childcol.For(c => c.SubCode).HeaderText("Codice Sub");
        childcol.For(c => c.SubDescription).HeaderText("Descrizione");
    })
    .Features(childfeat=>
        {
            childfeat.Updating()
                .StartEditTriggers(GridStartEditTriggers.DblClick)
                .ColumnSettings(childcolset =>
                {
                    childcolset.ColumnSetting().ColumnKey("Id").Required(true);
                    childcolset.ColumnSetting().ColumnKey("SubCode").Required(true);
                    childcolset.ColumnSetting().ColumnKey("SubDescription").Required(true);                   
                });
        });
})
.DataBind()
.Render())                              

<script type="text/javascript">
    $("#grid1").live('iggridupdatingrowadded', function () {
        $("#grid1").igGrid("saveChanges");
    });

    $("#grid1").live('iggridupdatingeditrowended', function (event, ui) {
        if (ui.rowAdding == false) {
            $("#grid1").igGrid("saveChanges");
        }
    });

    $("#grid1").live('iggridupdatingrowdeleted', function () {
        $("#grid1").igGrid("saveChanges");
    });
</script>                      

 

So, if I add, edit or delete a row my controller action receives a JSON transaction where I can find these information. But if I add, edit or delete a child row, what my controller action receives is an empty pramater. Here is my action:

 

public ActionResult UpdateData(string ig_transactions)
{
    ArrayList transactions = (ArrayList)Procurios.Public.JSON.JsonDecode(ig_transactions);

    foreach (Hashtable t in transactions)
    {
        switch (t["type"].ToString())
        {
            case "newrow":
            case "row":
                // Do Something...
                break;

            case "deleterow":
                // Do Something...
                break;
        }
    }

    JsonResult result = new JsonResult();
    Dictionary<string, bool> response = new Dictionary<string, bool>();
    response.Add("Success", true);
    result.Data = response;

    return result;
}

 

Take care that UI works correctly: I can see added rows, edited rows and deleted rows not only on main columns, but also on child ones. But of corse it is just a graphical way: if I refresh the page only main columns have been correctly updated, while child ones not.

Am I doing something wrong? Probably I have to define other event binders for child columns...or is there the possibility to define a different UpdateUrl for children?

 

Thanks in advance!

 

Flavio

 

 

Parents Reply Children
No Data