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

manual change page?

2 Answers 1780 Views
Grid
This is a migrated thread and some comments may be shown as answers.
steven
Top achievements
Rank 1
steven asked on 30 Oct 2012, 02:56 AM
Hi, I'm trying to figure out how I could load a grid and read a cookie and move the grid to a page from the value stored in the cookie.

I'm currently able to grab the page number through some code I found:

dataBound: function (e) {pageNum = this.dataSource.page(); $.cookie('jobpagenum', pageNum); },


now when the page reloads, I want to be able to tell the grid to switch over to that page.

any help?

thanks
steve

2 Answers, 1 is accepted

Sort by
0
Muthu
Top achievements
Rank 1
answered on 30 Oct 2012, 06:08 AM
Try this
function refreshPageSize(pageNum ) {
          
            var grid = $('#Grid').data('kendoGrid');
            grid.dataSource.pageSize(parseInt(pageNum ));
            grid.dataSource.page(1); // PageTo
            grid.dataSource.read();
            // refreshes the grid
            grid.refresh();          
        }
0
steven
Top achievements
Rank 1
answered on 30 Oct 2012, 04:54 PM
Thank you got me a little further, but the example below didnt work exactly how I wanted it.

I found that adding "page:" in dataSource would allow me to page directly to whatever page number I put in there.

I tried to stick a function in there like how I filter the read data from the cookie, but that didnt work either.

I ended up using some server code to read the cookie and this works.

steve



$("#grid").kendoGrid({
dataSource: {
page: <cfoutput><cfif isdefined("cookie.jobpagenum")>#cookie.jobpagenum#<cfelse>1</cfif></cfoutput>,
   transport: {
read: {
url: "jobsJson.cfm",
dataType: "json",
data: [
  {"jobid": function() { return $("#jobid").val()}},
  {"skillid": function() { return $("#skillid").val()}},
  {"company": function() { return $("#company").val()}},
  {"location": function() { return $("#locationid").val()}},
  {"jobtitle": function() { return $("#jobtitle").val()}},
  {"companycity": function() { return $("#companycity").val()}},
  {"consultantid": function() { return $("#consultantid").val()}},
  {"intInactive": function() { return $("#intInactive").val()}},
  {"intAcceptVisa": function() { return $("#intAcceptVisa").val()}},
  {"jobTypeID": function() { return $("#jobTypeID").val()}}     ]
}},
schema: {
model: {
id: "jobid",
fields: {
jobid: { type: "number" },
  jobtitle: {type: "string"},
skill: {type: "string"},
companyname: {type: "string"},
location: {type:"string"},
companycity: {type:"string"},
lastname: {type:"string"},
jobtype: {type:"string"},
dateadded: {type:"date"},
submittals: {type:"number"}
}
}
},
pageSize: 25,
},
height: 700,
     rowTemplate: kendo.template($("#rowTemplate").html()),
altRowTemplate: kendo.template($("#rowTemplateAlt").html()),
filterable: true,
sortable: true,
pageable: true,
dataBound: function (e) {pageNum = this.dataSource.page(); $.cookie('jobpagenum', pageNum); },
columns: [{field: "jobid", title:"ID", width: 50},
 {field: "jobtitle", title:"Title", width: 300},
 {field: "skill", title:"Specialty", width: 150},
 {field: "companyname", title:"Company", width: 200},  
 {field: "location", title:"State", width: 75},    
 {field: "companycity", title:"City", width: 100},
 {field: "lastname", title:"Consultant", width: 100},
 {field: "jobtype", title:"Job Type", width: 100},
 {field: "dateadded", title:"Added On", width: 100, template: '#= kendo.toString(dateadded,"MM/dd/yyyy") #'},    
 {field: "submittals", title:"Submittals", width: 75}
],
editable: "popup"

});

<!---             var grid = $("#grid").data('kendoGrid');
            grid.dataSource.pageSize(25);
            grid.dataSource.page(5); // PageTo
            grid.dataSource.read();
            // refreshes the grid
            grid.refresh();
alert('ran refresh');  --->          


});
</script
Tags
Grid
Asked by
steven
Top achievements
Rank 1
Answers by
Muthu
Top achievements
Rank 1
steven
Top achievements
Rank 1
Share this question
or