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

Server side Paging Kendo grid mvc

5 Answers 4180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
iliya
Top achievements
Rank 1
Veteran
iliya asked on 31 Oct 2020, 09:54 AM

I am developing a server side grid page ,i have googled it and did not find the correct behavior for me,

I need to each page size change dynamically and also the total number be set not via result len because i want to show user  that we have for example 10000 pages but each time send him only 100 when i do so if my page size is 100

               
         .DataSource(dataSource => dataSource
        .Custom()
        .Type("aspnetmvc-ajax")
        .ServerPaging(true)        
        .ServerSorting(true)
        .ServerFiltering(true) 
        .Transport(transport => transport
            
            .Read(read => read.Action("GetTodaysSalesList", "Sales")                              
            .Data("filterData"))

        )
        
        .Schema(schema => schema.Model(model =>
        {
            model.Id(p => p.RowID);
            model.Field(p => p.InvestorID).Editable(true);
            model.Field(p => p.LoanNumber).Editable(false);
            model.Field(p => p.LoanStatus).Editable(false);
            model.Field(p => p.LoanCategory).Editable(false);
            model.Field(p => p.CRBFundedDate).Editable(false);
            model.Field(p => p.NoteDate).Editable(false);
            model.Field(p => p.LoanAmount).Editable(false);
            model.Field(p => p.NetFunding).Editable(false);
            model.Field(p => p.Rate).Editable(false);
            model.Field(p => p.XIRR).Editable(false);
            model.Field(p => p.DateOfSale).Editable(false);
            model.Field(p => p.DaysOutstanding).Editable(false);
            model.Field(p => p.AccruedInterest).Editable(false);
            model.Field(p => p.CRBOriginationFee).Editable(false);
            model.Field(p => p.ImputedInterest).Editable(false);
            model.Field(p => p.Platform).Editable(false);
        }).Data("Data").Total("Total"))          

this controller side i have tried some options

option one:

   var test = _loans.ToDataSourceResult(request);
                test.Total = 1000;
                return   Json(test, JsonRequestBehavior.AllowGet);

 option two

              
                return   Json( new {Data=loans.ToDataSourceResult(request) Total=10}, JsonRequestBehavior.AllowGet);

 

 

the total has no influnce

5 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 04 Nov 2020, 07:42 AM

Hi, Iliya,

Thank you for the provided code snippets.

With this definition the data source will issue a request without a page size so when this line executes on the server, all records will be returned:

  var test = _loans.ToDataSourceResult(request);

At this point of execution, test will look like this:

{ Data: [{},{},{}], Total: 100000 }

If you want to use the ToDataSourceResult() extension method but return a different total, then you need to change the underlying Data property count to match the new Total and provide the same number as a value for the Total property:

public IActionResult Tasks_Read([DataSourceRequest] DataSourceRequest request)
{
      request.PageSize = 10;
     // setting the PageSize here will produce 10 records in the next line
      var result = tasks.ToDataSourceResult(request).Data;
            
      return Json(new { Data = result, Total = 10 });
}

For better understanding, take a look at the Custom Ajax Binding article:

https://docs.telerik.com/aspnet-mvc/html-helpers/data-management/grid/binding/custom-binding

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
iliya
Top achievements
Rank 1
Veteran
answered on 04 Nov 2020, 02:29 PM

Hi

thx for help i think i have  figured it out tout,

Can u help me with one more thing

I am trying to get row index when check box is checked ,not uid or id the row index  only when check box is checked or uncheck

this what i tried :

 

columns.Template(@<text></text>).ClientTemplate("<input onclick='checkObj(this)' type='checkbox'  class='chkbx'  data-investorName='#= InvestorName #' data-loan-number='#= LoanNumber #' " +
"data-customerid='#= LoanCustomerId #' data-rowid ='#= RowID#' " + " data-investorName='#= InvestorName #'/>")


 

 function checkObj( checkObj) {

 var grid = $("#sale-grid").data("kendoGrid");
                            var pageNum = grid.dataSource.page();
                            var RowId = $(checkObj).attr("data-rowid");



                            var dataItem = grid.dataSource.get(RowId);

                            var roww = grid.tbody.find("tr[data-uid='" + dataItem.uid + "']");
                            var rowIdxX = $("tr", grid).index(roww);
                            var dataRows = grid.items();
                            var rowIndex = dataRows.index(grid.select());


}
nothing helps rowIndex aways -1

 

0
Alex Hajigeorgieva
Telerik team
answered on 06 Nov 2020, 10:36 AM

Hello, Iliya,

To get the row index out of the rows that are rendered at the moment, you may use a similar workflow:

 function checkObj(checkbox){
        var row = $(checkbox).closest("tr");
        var gridRows = grid.items();
        var idx = gridRows.index(row);
        kendo.alert("Row index: " + idx);
      }

I believe in your case, the code does not work, because it is relying on the grid.select() method and it is likely that the grid is not selectable or it is multiple selectable in which case, you would also not get the desired outcome because the method would return an array.

Here is a sample Dojo for your convenience:

https://dojo.telerik.com/@bubblemaster/eSaMIHuv

Regards,
Alex Hajigeorgieva
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
iliya
Top achievements
Rank 1
Veteran
answered on 08 Nov 2020, 05:05 PM

Hi

thx for replay really appritiate it,i have fired it out i am running jqery on checkbox id and setting id dynamicly and now i have the index for the checked  row 

function onDataBoundGrid(e) {

                            $("input[type='checkbox']").each(function (key, elem) {
                                if( $(elem).attr('id') != "checkAllBox")
                                {
                                    $(elem).attr('id', key-1)
                                }

                            });

}

 

now i have a different issue how can i achieve calling different action on controller to get the read action for grid per different Uri(different query string )

for exmple /home/todaysales/

call action one 

for exmple /home/todaysales/?customerId=1

difrrent action 

 

 

0
Alex Hajigeorgieva
Telerik team
answered on 10 Nov 2020, 04:22 PM

Hello, Iliya,

It is better if a new private support thread is opened for a non-related questions or a new forum thread.

I am not sure what is the scenario but if the grid read action is concerned calling that with different parameters is a way to go. We use this approach for our detail grids for example:

https://demos.telerik.com/aspnet-mvc/grid/detailtemplate

Read(read => read.Action("DetailTemplate_HierarchyBinding_Orders", "Grid", new { employeeID = "#=EmployeeID#" }))

Or it can be done by calling a JavaScript function:

https://docs.telerik.com/aspnet-mvc/html-helpers/data-management/grid/faq#how-can-i-send-values-to-my-action-method-when-binding-the-grid

Regards,
Alex Hajigeorgieva
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
iliya
Top achievements
Rank 1
Veteran
Answers by
Alex Hajigeorgieva
Telerik team
iliya
Top achievements
Rank 1
Veteran
Share this question
or