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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding with ajax on grid details template

Thread ID:

Created:

Updated:

Platform:

Replies:

126374 Oct 11,2016 03:26 PM UTC Oct 17,2016 08:52 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Manolo
Asked On October 11, 2016 03:26 PM UTC

Hi,

I need some similar at you example:

http://mvc.syncfusion.com/demos/web/grid/detailtemplate

But, i need bind the details template with an ajax request, but I can't load the data.

My javascript code:

<script type="text/javascript">
      function detailGridData(e) {
          var user = e.data["ID"];
          var data = getDetails(user);
          e.detailsElement.find("#detailGrid").ejGrid({
          dataSource: data,
          columns: [
                        { field: "ID" },
                        { field: "IdPerson" },
                        { field: "Order" },
                        {field: "Count"}
                   ]
         });
          e.detailsElement.find(".tabcontrol").ejTab();


          function getDetails(idUser) {
              $.ajax({
                  type: "POST",
                  url: "/Grid/GetDetailsUser",
                  data: { 'user': idUser },
                  datatype: "JSON",
                  success: function (result) {
                      return result;
                  },
                  error: function (jqXHR, textStatus, errorThrown) {
                      console.log(textStatus + ' ' + errorThrown);
                  }
              });
          }
}
</script>

I attach an example.

Thanks

Attachment: RowDetails_392281cb.zip

Jayaprakash Kamaraj [Syncfusion]
Replied On October 12, 2016 06:37 AM UTC

Hi Manolo, 
 
Thank you for contacting Syncfusion support. 
 
The cause of the issue is, an ajax success is called after the grid is rendered. To overcome this problem, bind grid in ajax success. Please refer to the below code example and modified sample.   

<script type="text/javascript"> 
      function detailGridData(e) { 
          var user = e.data["ID"]; 
          var x = e; 
          $.ajax({ 
              type: "POST", 
              url: "/Grid/GetDetailsUser", 
              data: { 'user': user }, 
              datatype: "JSON", 
              success: function (result) { 
                  var e = x; 
                  e.detailsElement.find("#detailGrid").ejGrid({ 
                      dataSource: result, 
                      columns: [ 
                                    { field: "ID" }, 
                                    { field: "IdPerson" }, 
                                    { field: "Order" }, 
                                    { field: "Count" } 
                      ] 
                  }); 
              }, 
              error: function (jqXHR, textStatus, errorThrown) { 
                  console.log(textStatus + ' ' + errorThrown); 
              } 
          }); 
 
          e.detailsElement.find(".tabcontrol").ejTab(); 
} 
</script> 


 
Regards, 
 
Jayaprakash K. 


Manolo
Replied On October 14, 2016 12:06 PM UTC

Thanks a lot

Jayaprakash Kamaraj [Syncfusion]
Replied On October 17, 2016 08:52 AM UTC

Hi Manolo,  
 
Thank for the update. 
 
Please get back to us if you need any further assistance.   
 
Regards,  
 
Jayaprakash K. 


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

;