SFDatagrid pagination is not working After the source changed.

Hi Team,

I am working on SFDatagrid with Pagination.

My Scenario is when the user click on the button the DataGrid data wants to refresh with  proper pagination. For the first time when the page load the SFDataGrid is working with pagination. but when the user click on the button the pagination is not working

I did small sample and attaching to this. In the sample i have button and SFDatagrid. onload the Datagrid will be loaded with some sample data after loading click on the search button the data is refreshing but not displaying until clicking on the DataGrid headers and pagination is not at all working after button click. can you help me to solve this issue..


Thanks

Praveen.


Attachment: Test_47c6e091.zip

4 Replies 1 reply marked as answer

KK Karthikraja Kalaimani Syncfusion Team June 28, 2021 01:01 PM UTC

Hi Praveen,

Currently, We are validating your requirement. We will validate and update the further details on or before 30th June 2021. We appreciate your patience until then. 

Regards,
Karthik Raja



KK Karthikraja Kalaimani Syncfusion Team June 30, 2021 06:49 PM UTC

Hi Praveen, 

We have checked the reported issue "Rows are not showing when change Collections at run time" and we discovered that you had created a new instance for OrderInfoCollection property and later added data to the OrderInfoCollection. Actually, we cleared paged source, paged count,etc when ItemSource property Of SfDataPager is Changed. So, in your case you we received a 0 count for a new Collection because you added a data after the instance is created. So, only the SfPager populated with 0 count and the Default rows, NumericButtons were not showing in the view. So, we suggest you to create a new collection and then popuplate the data and then add that new collection to OrderInfoCollection property. For more details, please refer to the below code snippets to overcome the issue. 

Code snippets : 
public class MainViewModel : BaseViewModel
    {
        public MainViewModel()
        {
            SearchCommand = new Command(async () =>
            {
                Search();
            });
            Get();
        }

        private void Search()
        {
            var collection = new ObservableCollection<OrderInfo>();
            Random r = new Random();
            var num = r.Next(100, 999);
            this.GenerateOrders(num,collection);
            OrderInfoCollection = collection;
           
        }

        private Command _searchCommand;

        public Command SearchCommand
        {
            get { return _searchCommand; }
            set { SetValue(ref _searchCommand, value); }
        }



        private ObservableCollection<OrderInfo> orderInfo;
        public ObservableCollection<OrderInfo> OrderInfoCollection
        {
            get { return orderInfo; }
            set { SetValue(ref orderInfo, value); }
        }
        private void Get()
        {
            var collection = new ObservableCollection<OrderInfo>();
            Random r = new Random();
            var num = r.Next(100, 999);
            this.GenerateOrders(num, collection);
            OrderInfoCollection = collection;
        }
        private int _pageSize;

        public int PageSize
        {
            get { return _pageSize; }
            set { SetValue(ref _pageSize, value); }
        }

        private void GenerateOrders(int num,ObservableCollection<OrderInfo> orderInfos)
        {
            orderInfos.Add(new OrderInfo(num + 1001, "Maria Anders", "Germany", "ALFKI", "Berlin"));
            orderInfos.Add(new OrderInfo(num + 1002, "Ana Trujillo", "Mexico", "ANATR", "Mexico D.F."));
            orderInfos.Add(new OrderInfo(num + 1003, "Ant Fuller", "Mexico", "ANTON", "Mexico D.F."));
            orderInfos.Add(new OrderInfo(num + 1004, "Thomas Hardy", "UK", "AROUT", "London"));
            orderInfos.Add(new OrderInfo(num + 1005, "Tim Adams", "Sweden", "BERGS", "London"));
            orderInfos.Add(new OrderInfo(num + 1006, "Hanna Moos", "Germany", "BLAUS", "Mannheim"));
            orderInfos.Add(new OrderInfo(num + 1007, "Andrew Fuller", "France", "BLONP", "Strasbourg"));
            orderInfos.Add(new OrderInfo(num + 1008, "Martin King", "Spain", "BOLID", "Madrid"));
            orderInfos.Add(new OrderInfo(num + 1009, "Lenny Lin", "France", "BONAP", "Marsiella"));
            orderInfos.Add(new OrderInfo(num + 1010, "John Carter", "Canada", "BOTTM", "Lenny Lin"));
            orderInfos.Add(new OrderInfo(num + 1011, "Laura King", "UK", "AROUT", "London"));
            orderInfos.Add(new OrderInfo(num + 1012, "Anne Wilson", "Germany", "BLAUS", "Mannheim"));
            orderInfos.Add(new OrderInfo(num + 1013, "Martin King", "France", "BLONP", "Strasbourg"));
            orderInfos.Add(new OrderInfo(num + 1014, "Gina Irene", "UK", "AROUT", "London"));
            orderInfos.Add(new OrderInfo(num + 1031, "Maria Anders", "Germany", "ALFKI", "Berlin"));
            orderInfos.Add(new OrderInfo(num + 1032, "Ana Trujillo", "Mexico", "ANATR", "Mexico D.F."));
            orderInfos.Add(new OrderInfo(num + 1033, "Ant Fuller", "Mexico", "ANTON", "Mexico D.F."));
            orderInfos.Add(new OrderInfo(num + 1034, "Thomas Hardy", "UK", "AROUT", "London"));
            orderInfos.Add(new OrderInfo(num + 1035, "Tim Adams", "Sweden", "BERGS", "London"));
            orderInfos.Add(new OrderInfo(num + 1036, "Hanna Moos", "Germany", "BLAUS", "Mannheim"));
            orderInfos.Add(new OrderInfo(num + 1037, "Andrew Fuller", "France", "BLONP", "Strasbourg"));
            orderInfos.Add(new OrderInfo(num + 1038, "Martin King", "Spain", "BOLID", "Madrid"));
            orderInfos.Add(new OrderInfo(num + 1039, "Lenny Lin", "France", "BONAP", "Marsiella"));
            orderInfos.Add(new OrderInfo(num + 1030, "John Carter", "Canada", "BOTTM", "Lenny Lin"));
            orderInfos.Add(new OrderInfo(num + 1031, "Laura King", "UK", "AROUT", "London"));
            orderInfos.Add(new OrderInfo(num + 1032, "Anne Wilson", "Germany", "BLAUS", "Mannheim"));
            orderInfos.Add(new OrderInfo(num + 1033, "Martin King", "France", "BLONP", "Strasbourg"));
            orderInfos.Add(new OrderInfo(num + 1034, "Gina Irene", "UK", "AROUT", "London"));

            PageSize = Convert.ToInt32(Math.Ceiling(orderInfos.Count / 10M));
        }

    }
 
Regards,
Karthik Raja

Marked as answer

PR Praveen replied to Karthikraja Kalaimani July 2, 2021 05:15 PM UTC

HI Karthikraja Kalaimani

Thanks for the help.. It is working fine now. 

I have one more query in datagrid, i am planning to add Sl No.(Serial Number) Column to Datagrid, While i am sending the SL No from the code it is displaying wrongly when the user click on any column sorting. so is there any functionality to set the serial number from the datagrid based on the pagination and also when the user click on column sorting it wants to work.



MA Mohanram Anbukkarasu Syncfusion Team July 5, 2021 12:35 PM UTC

Hi Praveen, 

Thanks for the update.  

You can display serial number for the records in the DataGrid by customizing the RowHeader to display the row index in it. Please refer the below given knowledge base documents.  

References :  

Please revert to us with details, if this doesn’t meet your requirement.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon