jquery - Ajax and pagination -
trying implement ajax pagination dialecting grails controller:
1) ajax function refresh grid:
function refreshgridajax() { $("#filescontainer").find("#paginate a").live('click', function(event) { event.preventdefault(); var r = $(".curfolderid").text(); var url = $("#filescontainer").load("${request.contextpath}/files/listobjects?folderid="+r); //url = $(this).attr('href'); showspinner(); $.ajax({ type: 'get', url: url, success: function(data) { $('.curfolder').text($('.curfolder').text()); $("#filescontainer").fadeout('fast', function() {$(this).html(data).fadein('slow');}); }, complete: function(data) { hidespinner(); } }) }); }
2) controller method called ajax events parse folders, needs update paginate links well
// ajax load of specified objects def listobjects() { params.max = math.min(params.max ? params.int('max') : 10, 100) params.offset = params.offset ? params.offset.tointeger() : 0 string path = params?.folderpath long folderid = (params.folderid) ? params.folderid.tolong() : null list<files> files def user = springsecurityservice.currentuser def key = user.datastore.keyname def recipients = filesservice.getallrecipients(datastoreservice.getcurrentds()) def currentauth = springsecurityservice.authentication def acl = [] def parentfolder = files.findnamebyid(folderid) map<files, boolean> hasdelete = [:] map<files, boolean> hasadmin = [:] map<files, acl> aclfile = [:] map<files, string> ownerfile = [:] // return xml tree // getxmltree(key,params) if(folderid) { files = filesservice.getfilesbynodeid(folderid,params) } else { files = filesservice.getfilesbyparentname(key,params) } def nbfiles = filesservice.gettotal(folderid,key) if (files) { (files f:files) { hasdelete[f] = aclutilservice.haspermission(currentauth, f, has_delete) hasadmin[f] = aclutilservice.haspermission(currentauth, f, has_admin) aclfile[f] = aclutilservice.readacl(f) ownerfile[f] = aclutilservice.readacl(f).getowner().collect { it.properties.findall{it.key != 'class'} } } } //files = files.list(params) render (template:'/_common/list/files',model:[files: files,hasdeletepermission: hasdelete, hasadminpermission: hasadmin,bucketname:user.datastore.bucket,path:path,parentfolder:parentfolder,folderid:folderid,user:user,nbfiles:nbfiles,aclfile:aclfile,ownerfile:ownerfile,recipients:recipients,permissions:listpermissions()]) }
the first init loads folder, afterwards it's ajaxified. thus, self reference href dom object $(this).attr('href') make pagination working first loaded url, , params not refreshed after moving new folder (this alslo implemented in ajax , works fine).
any please?
Comments
Post a Comment