java 分页ajax,让will_paginate的分页支持ajax

#-----------------------------------------#will_paginate插件的ajax分页#-----------------------------------------@@pagination_options={:class=>'pagination',:prev_label=>'上一页',:next_label=>'下一页',:inner_window=>4,#links around the current page:outer_window=>1,#links around beginning and end:separator=>'',#single space is friendly to spiders and non-graphic browsers:param_name=>:page,#add by chengang:update=>nil,#ajax所要更新的html元素的id:url_suffix=>''#url的后缀,主要是为了补全REST所需要的url#add end}

mattr_reader:pagination_options

def will_paginate_remote(entries=@entries,options={})

total_pages=entries.page_countiftotal_pages>1options=options.symbolize_keys.reverse_merge(pagination_options)

page,param=entries.current_page,options.delete(:param_name)

inner_window,outer_window=options.delete(:inner_window).to_i,options.delete(:outer_window).to_i#add by chengangupdate=options.delete(:update)

suffix=options.delete(:url_suffix)

url=request.env['PATH_INFO']

url+=suffixifsuffix#add endmin=page-inner_windowmax=page+inner_windowifmax>total_pages thenmin-=max-total_pages

elsifmin<1thenmax+=1-minendcurrent=min..maxbeginning=1..(1+outer_window)

tail=(total_pages-outer_window)..total_pages

visible=[beginning,current,tail].map(&:to_a).flatten.sort.uniq

links,prev=[],0visible.eachdo|n|nextifn<1breakifn>total_pages

unless n-prev>1prev=n#change by chengangtext=(n==page?n:"[#{n}]")

          links<'redoendend#change by chenganglinks.unshift page_link_remote_or_span(entries.previous_page,'disabled',options.delete(:prev_label),param,update,url)

links.push    page_link_remote_or_span(entries.next_page,'disabled',options.delete(:next_label),param,update,url)#change endcontent_tag:div,links.join(options.delete(:separator)),optionsendendprotecteddef page_link_remote_or_span(page,span_class,text,param,update,url)

unless page

content_tag:span,text,:class=>span_classelselink_to_remote text,:update=>update,:url=>"#{url}?#{param.to_sym}=#{page}",:method=>:getendend

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值