Adding default (not user-inputted) data into a new grid line.

I need to auto populate three fields when a new record is added to the grid using the Plus + button on the grids edit menu. The contents of two of these fields, JobID and StackID, are passed into the controller.cs as part of the URL string. 

E.g.

        [HttpGet]

        public ActionResult Index(string jobID, string stackID, int? testTypeID)

The testTypeID value will always be a static ‘5’ in this instance, and this is ok.

 

How do I insert the current jobID and stackID values into a new grid line?

I’ve added this ClientSideEvents type to the @(Html.EJ().Grid

.ClientSideEvents(eve => eve.ActionComplete("actionComplete").ActionBegin("actionBegin"))

This then calls the following JavaScript which I want to populate a new record with the three values.

    function actionBegin(args) {

        if ((args.requestType == "add")) {

            args.data["JobID"] = this.JobID;

            args.data["StackID"] = this.StackID;

            args.data["TestTypeID"] = 5;

        }

    }

This isn’t currently working as I’m not sure how I get JobID and StackID values into the add data.

 

I’m using MVC with EJ1

 

 

 


7 Replies

MP Manivannan Padmanaban Syncfusion Team February 17, 2020 02:54 PM UTC

Hi Garry, 

Greetings from Syncfusion Support. 

Query: Adding default (not user-inputted) data into a new grid line. 

Using default column property of ejGrid, we can able to add the default value while adding the new record. Kindly refer the below help documentation link for more details, 

And also, you have mentioned that “I’m not sure how I get JobID and StackID values into the add data.” We are quite unclear about this query. So, please get back to us with the below details. 

  1. Share the complete Grid code example.
  2. Confirm whether you want to receive the values from the controller page and need to set the same while adding new record.
  3. Explain your requirement in detail.

Provided details will help us, to achieve your requirement as early as possible. 

Regards, 
Manivannan Padmanaban. 



GG Garry Grierson February 20, 2020 05:33 PM UTC

Hello,

Basically what I wanted to do was pass the ViewBag.jobID, and ViewBag.stackID data into the grid as Default values, but it didn't seem to like me doing this.

I've now just circumvented this by passing the above two values into hidden text fields on the cshtml page.
I'm just assuming what I tried to do can't be done with a grid.

Thanks for the reply.


GL Gowri Loganathan Syncfusion Team February 21, 2020 01:44 PM UTC

Hi Garry, 

Thanks for the update. 

Query#:Adding default (not user-inputted) data into a new grid line - I wanted to do was pass the ViewBag.jobID, and ViewBag.stackID data into the grid as Default values, but it didn't seem to like me doing this.

We have checked the query at our end and it is possible to pass the ViewBag.jobID and ViewBag.stackID data into the grid as Default values in the controller page and set it as default value in the grid column field to which you want to show when on perform adding and editing operation.


Code snippet 
 
 
Index.cshtml 
 
  ………….  .. . . 
.Columns(col => 
                  { 
                      col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add(); 
                      col.Field("CustomerID").HeaderText("CustomerID").DefaultValue(ViewBag.stackID).Add(); 
                      col.Field("EmployeeID").HeaderText("Employee ID").DefaultValue(ViewBag.jobID).Add(); 
                      col.Field("ShipCity").HeaderText("Ship City").Add(); 
                      col.Field("ShipCountry").HeaderText("Ship Country").Add(); 
                  })) 
 
…………. . .  .  
 
Homecontroller.cs 
 
     public ActionResult Index() 
        { 
            if (order.Count() == 0) 
                BindDataSource(); 
            ViewBag.data = order; 
            ViewBag.stackID = "testStack";       //set the stackID value here 
            ViewBag.jobID = "testJob";         // set the jobID value here 
            return View(); 
        } 
 
 
Sreenshot: 

 


Please revert us, if you need more assistance on this. 

Regards, 
Gowri V L. 



GG Garry Grierson February 21, 2020 01:49 PM UTC

Thanks, I'll have another look at this.


GL Gowri Loganathan Syncfusion Team February 24, 2020 05:10 AM UTC

  
  
  
Hi Garry, 
  
  
  
Thanks for the update. 
  
Please get back to us, if you  need more assistance on this. 
  
  
  
Regards, 
  
Gowri V L. 
  



CA Carlos December 2, 2021 06:12 PM UTC

Using ForeingKeyfield this does not work!!




PS Pon Selva Jeganathan Syncfusion Team December 3, 2021 01:24 PM UTC

Hi Carlos, 

Thanks for contacting syncfusion forum. 

Query: Using ForeingKeyfield this does not work


We checked your query by preparing sample with Foreignkeyfield, but we were unable to reproduce the issue at our end.  

Please refer to the below screenshot, 

 


Please refer to the below attached sample 

After following the above reference, still faced issue please share us the following details.

  1. Share the complete Grid code example.
  2. Share the detail explanation of your issue
  3. Share the product version details.
  4. If possible, reproduce the issue in the attached sample or share the issue reproducible sample.
  5. Share the video demo/screenshot of the issue.
 
The provided information will be helpful to provide you response as early as possible.   

Regards, 
Pon selva 
 


Loader.
Up arrow icon