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. Image for the cookie policy date

Grid Header

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

5 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team 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 
 



RD Richard Dublon 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?


PK Prasanna Kumar Viswanathan Syncfusion Team 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 
 



RD Richard Dublon 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?


PK Prasanna Kumar Viswanathan Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon