This is a migrated thread and some comments may be shown as answers.

Paging doesn't work with xml data binding

3 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ravi
Top achievements
Rank 1
Ravi asked on 08 Oct 2013, 03:10 PM
Hi,

I  am working on a prototype for our new project, after the approval of this prototype we will move ahead and buy the license.

I want to load the grid with data from xml file, display it with all features (sorting, paging, filtering, etc.)

Below is the code I use in Controller and Razor

        public ActionResult Index()
        {
            return View(GetQueueItems());
        }

        private static IEnumerable<TmpQueueModel> GetQueueItems()
        {
            IList<TmpQueueModel> ieTmpQueueModel = null;
            TmpQueueModel tmpQueueModel = null;
            try
            {
                DataSet dsQueue = new DataSet();
                dsQueue.ReadXml("\\App_Data\\Queue.xml");

                if (dsQueue.Tables[0].Rows.Count > 0)
                {
                    ieTmpQueueModel = new List<TmpQueueModel>();
                    foreach (DataRow dr in dsQueue.Tables[0].Rows)
                    {
                        tmpQueueModel = new TmpQueueModel();
                        tmpQueueModel.Action = dr["Action"].ToString();
                        //tmpQueueModel.AssignedDate = dr["AssignedDate"].ToString();
                        //tmpQueueModel.AssignedTo = dr["AssignedTo"].ToString();
                       // tmpQueueModel.Comment = dr["Comment"].ToString();
                        tmpQueueModel.ConsumerFirstName = dr["ConsumerFirstName"].ToString();
                        tmpQueueModel.ConsumerId = dr["ConsumerId"].ToString();
                        tmpQueueModel.ConsumerLastName = dr["ConsumerLastName"].ToString();
                        tmpQueueModel.ExternalReferenceID = dr["ExternalReferenceID"].ToString();
                        tmpQueueModel.First_Name = dr["First_Name"].ToString();
                        //tmpQueueModel.IsReserved = (bool)dr["IsReserved"];
                        tmpQueueModel.Last_Modified_Date_and_Time = dr["Last_Modified_Date_and_Time"].ToString();
                        tmpQueueModel.Last_Name = dr["Last_Name"].ToString();
                        tmpQueueModel.LastModifiedBy = dr["LastModifiedBy"].ToString();
                        tmpQueueModel.Medicaid_No_ = dr["Medicaid_No_"].ToString();
                        tmpQueueModel.No_ = dr["No_"].ToString();
                        tmpQueueModel.PacketReceivedDate = dr["PacketReceivedDate"].ToString();
                        //tmpQueueModel.QueueHistoryDate = Convert.ToDateTime(dr["QueueHistoryDate"]);
                        tmpQueueModel.QueueId = Convert.ToInt32( dr["QueueId"]);
                        //tmpQueueModel.QueueStatus = dr["QueueStatusId"].ToString();
                        ieTmpQueueModel.Add(tmpQueueModel);
                    }
                }
                return ieTmpQueueModel;
            }
            catch
            {
                return null;
            }
        }

        public ActionResult QueueItems_Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(GetQueueItems().ToDataSourceResult(request));
        }


----------XXXXXXXXXXX------------
@model IEnumerable<GenericQueue.Models.TmpQueueModel>

@(Html.Kendo().Grid(Model)    
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ConsumerId).Groupable(false);      
        columns.Bound(p => p.PacketReceivedDate);
        columns.Bound(p => p.First_Name );
        columns.Bound(p => p.Last_Name);        
    })
    .Groupable()
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()   
        .PageSize(5)
        .Read(read => read.Action("QueueItems_Read", "Grid"))    
    )
)


Thanks in advance.

Regards,
Ravi

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 10 Oct 2013, 11:06 AM
Hello Ravi,

The code for the Grid and the action methods looks correct. Is the data successfully read from the XML file and  are there any exceptions or JavaScript errors thrown when trying to page? From the code that you provided it seems that the path that you have provided to the ReadXml method is not absolute  so the file is probably not found. If that is the case then you could use code similar to the one in the snippet below to find the correct path:

var path = Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), "Queue.xml");
dsQueue.ReadXml(path);
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ravi
Top achievements
Rank 1
answered on 10 Oct 2013, 11:46 AM
The data is displayed initially but paging does not work.
0
Accepted
Ravi
Top achievements
Rank 1
answered on 10 Oct 2013, 11:47 AM
I just had to change code in Razor

Read(read => read.Action("QueueItems_Read", "Grid")
to
Read(read => read.Action("QueueItems_Read", "home")
and it worked.
Tags
Grid
Asked by
Ravi
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Ravi
Top achievements
Rank 1
Share this question
or