How do I format the total record count?

How do I format the total page number and the total record count so that If the value will use commas?

I want 1845 to appear as 1,845 and if 154 were 1540 I would want it to appear as 1,540


1 Reply 1 reply marked as answer

RR Rajapandi Ravi Syncfusion Team March 8, 2021 01:20 PM UTC

Hi Danyelle, 

Greetings from syncfusion support 

We have analyzed your query and we could see that you like to format the total page number and the total record count. So, based on your requirement we have prepared a sample and achieved your requirement by using dataBound event of Grid. Please refer the below code example and sample for more information. 


<script> 
    function bound() { //dataBound event of Grid 
            var totalPages = document.getElementsByClassName('e-parentmsgbar')[0].querySelector('.e-pagenomsg').innerText.split(' ')[2]; //get the total pagecount 
            var arr = document.getElementsByClassName('e-parentmsgbar')[0].querySelector('.e-pagenomsg').innerText.split(' '); 
            var regex = totalPages.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //insert commas by using regex 
            document.getElementsByClassName('e-parentmsgbar')[0].querySelector('.e-pagenomsg').innerText = arr[0].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " " + arr[1] + " " + regex + " " + arr[3] + " " + arr[4]; 
            var totalRecord = document.getElementsByClassName('e-parentmsgbar')[0].querySelector('.e-pagecountmsg').innerText.match(/(\d+)/)[0]; //get the total record count 
            var recordRegex = totalRecord.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //insert commas by using regex 
 
            document.getElementsByClassName('e-parentmsgbar')[0].querySelector('.e-pagecountmsg').innerText = "(" + recordRegex + " " + "items" + ")"; 
    } 
</script> 




Regards,
Rajapandi R 


Marked as answer
Loader.
Up arrow icon