We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid Header

Thread ID:

Created:

Updated:

Platform:

Replies:

129123 Feb 28,2017 02:05 PM UTC Apr 5,2017 06:16 AM UTC ASP.NET MVC 5
loading
Tags: Grid
Richard Dublon
Asked On February 28, 2017 02:05 PM UTC

Hi,
Is there a way to display the current date as a grid header(not a column header but the header of a grid)?

Thanks

Prasanna Kumar Viswanathan [Syncfusion]
Replied On March 1, 2017 04:35 PM UTC

Hi Richard, 

Thanks for contacting Syncfusion support. 

Yes, we can display the current date in grid header. It is achieved using create event of ejGrid.  

Find the code example, screenshot and sample:  

@(Html.EJ().Grid<object>("FlatGrid") 
  .Datasource((IEnumerable<object>)ViewBag.datasource) 
  .AllowPaging()  
  .Columns(col => 
   { 
      ---------------------- 
   }) 
      .ClientSideEvents(eve => { eve.Create("create"); }) 
  ) 
 
 
 
<script>   
    function create(args) { 
        $("#FlatGrid").prepend("<div>" + new Date() + "</div>"); 
    } 
</script> 

Screenshot:  

 


Refer to the Help document for the create event. 


Regards, 
Prasanna Kumar N.S.V 
 


Richard Dublon
Replied On March 17, 2017 02:21 PM UTC

Is there a way to pass that header value to the controller when I click the save button on the toolbar on my grid?

Prasanna Kumar Viswanathan [Syncfusion]
Replied On March 20, 2017 12:33 PM UTC

Hi Richard, 

Yes, we can pass the header value to the controller when click the save button on the toolbar. It is achieved by the toolbarClick event of ejGrid. In this event we check the condition with the itemName and pass the value to the controller using the ajaxPost.  

Find the code example and sample:  


@(Html.EJ().Grid<object>("FlatGrid") 
  .Datasource((IEnumerable<object>)ViewBag.datasource) 
  .AllowPaging() 
  -------------------------------------------- 
 .Columns(col => 
   { 
      ----------------------------------- 
   }) 
      .ClientSideEvents(eve => { eve.Create("create").ToolbarClick("toolbar"); }) 
  ) 
 
 
 
<script>   
    function create(args) { 
       $("#FlatGrid").prepend("<div id='Date'>" + new Date() + "</div>"); 
    } 
 
    function toolbar(args) { 
        if (args.itemName == "Update") { 
            $.ajax({ 
                url: "/Grid/Save", 
                type: "POST", 
                dataType: "json", 
                contentType: "application/json;charset=utf-8", 
                data: JSON.stringify({ "value": $("#Date").text() }), 
                success: function (e) { 
                    var a = e; 
                } 
            }); 
        } 
    } 
</script> 
 
----------------------------------------------------- 

public ActionResult Save(string value) 
        { 
            return Json(value, JsonRequestBehavior.AllowGet); 
        } 



Refer to the Help document for the toolbarClick event.  


If we misunderstood your query, please get back to us with elaborating the requirement. 

Regards, 
Prasanna Kumar N.S.V 
 


Richard Dublon
Replied On April 4, 2017 03:47 PM UTC

A followup question....
I am using batch update and I would like to be able to pass the date header like you have shown and also the updated grid cells to my controller all at the same time?  What is the syntax to do this?

Prasanna Kumar Viswanathan [Syncfusion]
Replied On April 5, 2017 06:16 AM UTC

Hi Richard, 

According to your requirement you need to pass the date header to the controller as an additional parameter. To achieve this, use custom adaptor in Grid. In the custom adaptor, the batchrequest method has to be overridden and pass the date as an additional parameter.  
 
Find the code example, screenshot and sample:  
 

@(Html.EJ().Grid<object>("FlatGrid") 
   .Datasource(d => d.URL("/Home/GetData").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor)) 
   .EditSettings(edit => edit.AllowEditing().EditMode(EditMode.Batch)) 
   ------------------------------ 
  .AllowPaging() 
   .Columns(col => 
   { 
       col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();   
       col.Field("ShipCity").Width(100).Add(); 
       col.Field("ShipCountry").Width(100).Add(); 
     
   }) 
    .ClientSideEvents(eve => { eve.Create("create").Load("load"); }) 
) 
 
<script> 
    function create(args) { 
        $("#FlatGrid").prepend("<div id='Date'>" + new Date() + "</div>"); 
    } 
    function load(args) { 
        this.model.dataSource.adaptor = new customAdaptor(); 
    } 
 
    var customAdaptor = new ej.UrlAdaptor().extend({ 
 
        batchRequest: function (dm, changes, e, query) { 
            var res = { 
                changed: changes.changed, 
                added: changes.added, 
                deleted: changes.deleted, 
                action: "batch", 
                table: e.url, 
                value: $("#Date").text(),  
                key: e.key 
            }; 
            ------------------------- 
           return { 
                type: "POST", 
                url: dm.dataSource.batchUrl, 
                contentType: "application/json; charset=utf-8", 
                dataType: "json", 
                data: JSON.stringify(res) 
            }; 
        } 
    }); 
 
</script> 

Screenshot:  

 


Refer to the Help document for the custom adaptor.  


Regards, 
Prasanna Kumar N.S.V 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;