-1

I am new to JqGrid and please help me with this request.

I have a 3 level hierarchical JqGrid setting as shown in the link. It is not exactly the same, but very similar. My requirement is to have the CustomerGrid's primary key also passed when OrderGrid is expanded.

Or in short, I would like to have

    public void SetUpThreeLevelGrids(ThreeLevelHierarchyJqGridModel model)
    {
        var customersGrid = model.CustomersGrid;

        // code here

        int cId;
        //cId = <CustomerId from the CustomerGrid>; //*****How to get this******
        ordersGrid.DataUrl = Url.Action("ThreeLevel_OrdersDataRequested", new { customerId =  cId });

        // code here
    }

I would like to use that variable passed to the ThreeLevel_OrderDetailsDataRequested method:

public JsonResult ThreeLevel_OrderDetailsDataRequested(int customerId, string parentRowID)
{
    // code here
}
user007
  • 1,504
  • 2
  • 18
  • 51

1 Answers1

0

I created a static variable named CustomerId in my Controller. I do not know whether this can break anything or not. I just wanted to make it work.

public static int customerId = 0;

In the Action method for the second grid, I assigned the CustomerId value.

public JsonResult ThreeLevel_OrdersDataRequested(string parentRowID)
{
    var northWindModel = new NorthwindDataContext();
    var model = new ThreeLevelHierarchyJqGridModel();
    customerId = int.Parse(parentRowID);
    SetUpThreeLevelGrids(model);

    //code
}

Accessed the global static variable in the third level grid.

public JsonResult ThreeLevel_OrderDetailsDataRequested(string parentRowID)
{    
    //Code
    var orderDetails = from o in myDbModel.MyCustomerOrderDetails
         where o.OrderID == Convert.ToInt32(parentRowID)
         and o.CustomerId == customerId //static global variable
         select o;

    //Code
}

If anyone has a better suggestion to get the 1st level table's selected primary key in the third level grid, please let me know.

user007
  • 1,504
  • 2
  • 18
  • 51