Save number of line by pages

Hello,

I'm using EJ2 grid and I need to save inside a cookie the number of lines by pages selected by the user. Before, with EJ1, I used this code :
// Mise à jour dans les coockies du pageSize de la grid
$(document).ready(function () {
    $(".e-grid .e-pager-itemsinterval .e-drpdwn.e-ul li").click(function () {
        var d = new Date()
        // Expiration : 365 jours
        d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000))
        var expires = "expires=" + d.toUTCString()
        document.cookie = $("#coockiePageSize").html() + "=" + $(this).text() + ";" + expires + ";path=/"
    });
});

But this doesn't work with EJ2


3 Replies

PS Pavithra Subramaniyam Syncfusion Team July 16, 2018 09:52 AM UTC

Hi Thibault, 
 
Thanks for contacting Syncfusion Support. 
 
We have checked your query and in Essential JavaScript 2 Grid component you can achieve your requirement by using dropDownChanged event of pager component. We have prepared a simple sample based on your requirement. Please refer to the below code example, Documentation link and sample link. 
 
[index.chtml] 
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => 
{ 
    .  .  . 
    col.Field("ShipCountry").HeaderText("Ship Country").Width("120").Add(); 
 
}).AllowPaging().PageSettings(page => { page.PageSizes(true); }).Render() 
 
<script> 
$(document).ready(function () { 
   var pager = document.querySelector(".e-grid .e-pager").ej2_instances[0]; 
    pager.dropDownChanged = function (e) { 
        var d = new Date() 
        // Expiration : 365 jours 
        d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000)) 
        var expires = "expires=" + d.toUTCString() 
        alert(e.pageSize); 
    }; 
}); 
</script> 
 
 
 
 
Regards, 
Pavithra S. 



TF thibault fouillat July 17, 2018 10:04 AM UTC

Hello,

It's working fine. 

Thanks


PS Pavithra Subramaniyam Syncfusion Team July 18, 2018 11:15 AM UTC

Hi thibault, 
 
Thanks for your update. 
 
We are glad to hear that the provided solution helps you. 
 
Please contact us if you have any queries. 
 
Regards, 
Pavithra S. 


Loader.
Up arrow icon