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

put pager on top of grid

Hi, 

I 've follow sample on how to How to render Pager at the Top of the Grid but it didn't work as expected. I need help to put pager at top page. please find my code below. in the code, .DataBound('dataBound') show error of (too many character in character literal) which produce when we put single quote for "dataBound" value. I've changed to double quote but still not working. 

<div class="control-section" style="width:96%;margin-left:0%;margin-right:1%">
        @Html.EJS().Grid("ProcessFailed").DataSource((IEnumerable<object>)ViewBag.List_ProcessFailed).AllowExcelExport().ShowColumnMenu(true).AllowFiltering().AllowSorting().ToolbarClick("toolbarClick_ProcessFailed").AllowReordering().Columns(col =>
                 {
                     col.Field("RowCount").HeaderText("No.").Visible(false).Width(80).Add();
                     col.Field("InMessageLogID").HeaderText("InMessageLogID").Width(200).Add();
                     col.Field("LoggedDate").HeaderText("LoggedDate").Width(120).Add();
                     col.Field("StatusID").HeaderText("Status Id").Width(200).Add();
                     col.Field("DocumentType").HeaderText("Document Type").Width(200).Add();
                     col.Field("CreatedByID").HeaderText("CreatedByID").Width(200).Add();
                     col.Field("CreatedDate").HeaderText("CreatedDate").Width(180).Add();
                     col.Field("XMLMessage").HeaderText("XMLMessage").Template("#viewXMLMessage").Width(200).Add();
                 }).AllowGrouping(true).AllowResizing(true).AllowPaging().DataBound('dataBound').PageSettings(page => page.PageCount(5).PageSize(10).PageSizes((new string[] { "5", "10", "20", "All" }))).FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu); }).Toolbar(new List<string>() { "ExcelExport" }).Render()
    
        <script>
            var initialGridLoad = true;
            function dataBound() {
                if (initialGridLoad) {
                    initialGridLoad = false;
                    var pager = document.getElementsByClassName('e-gridpager')
                    var toolbar = document.getElementsByClassName('e-toolbar')
                    grid.element.insertBefore(pager[0], toolbar[0]);
                }
            }
        </script>
    
    </div>

5 Replies

PS Pavithra Subramaniyam Syncfusion Team January 28, 2019 07:09 AM UTC

Hi Muhammad, 
 
Sorry for the inconvenience caused. 
 
To achieve your requirement you need to get the Grid instance before inserting the pager element in dataBound event. Please refer to the below code example for more information. 
 
[index.cshtml] 
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => 
   { 
       col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
       .  .  .   
 
   }).AllowPaging().AllowGrouping().DataBound("dataBound").Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render() 
 
<script> 
    var initialGridLoad = true; 
    function dataBound() { 
        if (initialGridLoad) { 
                var topElement; 
                initialGridLoad = false; 
                var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0]; 
                var pager = document.getElementsByClassName('e-gridpager'); 
                if (grid.allowGrouping || grid.toolbar) { 
                    topElement = grid.allowGrouping ? document.getElementsByClassName('e-groupdroparea') : 
                        document.getElementsByClassName('e-toolbar'); 
                } else { 
                    topElement = document.getElementsByClassName('e-gridheader'); 
                } 
                grid.element.insertBefore(pager[0], topElement[0]); 
            } 
        }  
</script> 
 
However, We will made changes in our documentation and these changes will be refreshed in any of our upcoming release. 
 
Please contact us if you need any further assistance. 
 
Regards, 
Pavithra S. 



AF afiqdoherty January 28, 2019 08:20 AM UTC

thank you so much for the reply. that solution works. :)

however, what I need is a little bit different if it is doable. I just need the Pager(drop down 5,10,20,All ) to be on top on the right side. the rest, remain at bottom. means that, Pager will be in same row as Excel Export toolbar. Please refer my picture below.



really appreciate if you can help me to solve this issue. :)))

Actually, the reason is I cannot find solution to maintain the Pager to stay center unless to set manually in .css style(using margin-left). But, the pager will not be in static position if the page numbering(on the left) is expanding. So, it will move the Pager further right. If you know what I mean. Hopefully if you can help me to maintain the Pager stays at center, regardless how long the page numbering is .
 
regards,

afiq


PS Pavithra Subramaniyam Syncfusion Team January 29, 2019 08:33 AM UTC

Hi Muhammad, 
 
We have analyzed your requirement and We suggest you to use the below codes in the “DataBound” event handler of Grid to achieve this requirement. Please refer the code below, 
 
 
   @Html.EJS().Grid("Grid")...DataBound("dataBound")...Render() 
 
   <script> 
       var initialGridLoad = true; 
       function dataBound() { 
        if (initialGridLoad) { 
            initialGridLoad = false; 
            var toolobj = document.getElementsByClassName("e-toolbar")[0].ej2_instances[0];   //Get instance of toolbar 
            toolobj.height = "60px"     //Set the height for the toolbar as required 
            var toolbar = document.getElementsByClassName('e-toolbar-items')[0]; 
            toolbar.classList.add("e-tbar-pos");   //add “e-tbar-pos” class in toolbar element             
            var pagesizedrop = document.getElementsByClassName('e-pagesizes')[0]; 
            pagesizedrop.classList.add("e-toolbar-right");  //add “e-toolbar-right” class to pagesize element 
            //append the page size drop down to toolbar 
           toolbar.appendChild(pagesizedrop); 
        } 
    } 
   </script> 
 
 
Documentations :  
 
Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 



AF afiqdoherty January 29, 2019 09:49 AM UTC

Thank you so much Pavithra S. ,  that works :D


PS Pavithra Subramaniyam Syncfusion Team January 29, 2019 09:52 AM UTC

Hi Muhammad,  

Thanks for your update.  

We are happy to hear that the provided information was helpful.  

Please contact us if you need any further assistance. As always, we will be happy to assist you.  

Regards,  
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon