This is a migrated thread and some comments may be shown as answers.

[Solved] Reloading data in a Foreign Key Column

2 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ezequiel
Top achievements
Rank 2
Ezequiel asked on 25 Apr 2012, 07:52 PM
I have a grid with two dependent columns, one I have a ClientTemplate where the user can search for a customer.
When selected a customer I need to load the other column with only Items of that Customer.

columns.Bound(c => c.CustomerCode)
                       .ClientTemplate(string.Format("<#= CustomerCode!= null ? CustomerCode.Code - CustomerCode.Name:''#>"))
                       .Width(210);
                columns.ForeignKey((f => f.CustomerItemId), (IEnumerable)this.ViewData["CustomerItemId"], "Id", "Name").Width(175);

This javascript is used to set the value of the fields after selecting the CustomerCode.
function onChangeLookUpFieldCustomerCode(e) {
            var urlAction = '<%= this.Url.Action("GetCustomer", "../AjaxCombo") %>';
            $.ajax({
                url: urlAction,
                type: 'POST',
                data: { customerCode: e.value },
                complete: null,
                success: function(data) {
                    if (data.Nome != "") {
                        $('#CustomerCode_Name').val(data.Name);
                    }
                    else {
                        alert('Customer not found');
                        $('#CustomerCode_Name').val('');
                    }
                }
            });
        }

In the AjaxComboController  where I get the Customer data I'm setting:
this.ViewData["CustomerItemId"] = itemList;

How can I populate the data for the CustomerItem Column?

2 Answers, 1 is accepted

Sort by
0
Samantha
Top achievements
Rank 1
answered on 23 May 2012, 08:27 AM
anyone? I badly need the solution for this 
0
Dalbir
Top achievements
Rank 1
answered on 02 Aug 2012, 03:34 AM
Where you are updating data for the foreign key column (client side), after you update data, update the grid foreign key column data using this:

grdObject = $('#grdObjectID').data('tGrid');
grdObject.columns[1].data = data;

grdObjectID is the name of the grid,
Use columns Index as to use which column. This will update your foregin key columns data client side.

Also you can use Grid's onEdit method to use the lastest client side updated model
function OnPayeeMappingGridEdit(e) {
    var drop = $("#grdObjectID .t-dropdown input").data("tDropDownList");
    drop.dataBind(lstData);
}

Bind OnPayeeMappingGridEdit  as onEdit handler at grid
lstData is JSON object loaded client side using ajax post just when you update the model at client side.
Tags
Grid
Asked by
Ezequiel
Top achievements
Rank 2
Answers by
Samantha
Top achievements
Rank 1
Dalbir
Top achievements
Rank 1
Share this question
or