업데이트 된 잔액을 사용하여 명세서의 일부 레코드를 일시적으로 숨기고 싶습니다.테이블 레코드를 임시로 숨기기 4.2
아래와 같이 이해를 돕기 위해 스크린 샷을 참조하십시오. 내가 숨기기 버튼을 클릭하면
은 내가 원하는, 그것은 완전히 행을 숨길해야하며, 균형을 이월해야하며 클릭 모든를 표시 할 때 그것은 모든 레코드를 표시해야합니다.
테이블에 숨겨진 필드를 만들고 컨트롤러에 hide_xvaziri 메서드를 작성했지만 숨기기 button_to 함수와 혼동하여 '/ xvaziri/: id/hide'를 가져 오려면 'xvaziris # hide_xvaziri'
20160729062246_add_hidden_to_xvaziris.rb
class AddHiddenToXvaziris < ActiveRecord::Migration
def change
add_column :xvaziris, :hidden, :boolean, :default => false
end
end
xvaziris_controller.rb
class XvazirisController < ApplicationController
before_action :set_xvaziri, only: [:show, :edit, :update, :destroy]
def index
@xvaziris = Xvaziri.find_by hidden: false
@xvaziris = Xvaziri.search(params[:search])
respond_to do |format|
format.js
format.html
end
end
def import
Xvaziri.import(params[:file])
redirect_to xvaziris_url, notice: "Xvaziris imported."
end
def show
end
def new
@xvaziri = Xvaziri.new
end
def create
@xvaziri = Xvaziri.new(xvaziri)
if
@xvaziri.save
flash[:notice] = 'Xvaziri Created'
redirect_to @xvaziri
else
render 'new'
end
end
def edit
end
def update
if @xvaziri.update(xvaziri)
flash[:notice] = 'Xvaziri Updated'
redirect_to @xvaziri
else
render 'edit'
end
end
def destroy
@xvaziri.destroy
flash[:notice] = 'Xvaziri was successfully destroyed.'
redirect_to xvaziris_url
end
def hide_xvaziri
@xvaziri = Xvaziri.find(params[:id])
@xvaziri.hidden = true
flash[:notice] = 'Xvaziri was successfully hidden.'
redirect_to xvaziris_url
end
def reset_filter
xvaziris = Xvaziri.all
xvaziris.each do |xvaziri|
xvaziri.hidden = false
end
redirect_to xvaziris_url
end
private
# Use callbacks to share common setup or constraints between actions.
def set_xvaziri
@xvaziri = Xvaziri.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def xvaziri
params.require(:xvaziri).permit(:date, :description, :amount, :discount, :paid)
end
end
index.html.erb
01 23,516,<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="table-responsive myTable">
<table id = "kola" class="table listing text-center">
<thead>
<tr class="tr-head">
<td>Description</td>
<td>Amount</td>
<td>Discount</td>
<td>Paid</td>
<td>Balance</td>
<td>Button</td>
</tr>
</thead>
<tbody>
<%= render @xvaziris %>
</tbody>
</table>
</div>
</div>
</div>
<%= link_to "Show all", xvaziri_resetfilter_path %>
_xvaziri.html.erb
<tr class="tr-<%= cycle('odd', 'even') %>">
<td class="col-3"><%= span_with_possibly_red_color xvaziri.description %></td>
<td class="col-1"><%= number_with_precision(xvaziri.amount, :delimiter => ",", :precision => 2) %></td>
<td class="col-1 neg"><%= number_with_precision(xvaziri.discount, :delimiter => ",", :precision => 2) %></td>
<td class="col-1 neg"><%= number_with_precision(xvaziri.paid, :delimiter => ",", :precision => 2) %></td>
<% @balance += xvaziri.amount.to_f - xvaziri.discount.to_f - xvaziri.paid.to_f %>
<% color = @balance >= 0 ? "pos" : "neg" %>
<td class="col-1 <%= color %>"><%= number_with_precision(@balance.abs, :delimiter => ",", :precision => 2) %></td>
<td class="col-1"><%= button_to "Hide", '#', :method => "get" %></td>
</tr>
routes.rb
Rails.application.routes.draw do
root 'xvaziris#index'
resources :xvaziris do
collection { post :import }
end
get '/xvaziri/:id/hide', to: 'xvaziris#hide_xvaziri'
get '/xvaziri/resetfilter', to: 'xvaziris#reset_filter'
end
어떤 제안이 가장 환영합니다.
미리 감사드립니다.
답장을 보내 주셔서 감사합니다. jquery로 행을 숨긴 후에 잔액을 가져올 수 있습니까? –
ajax 호출을 구현해야합니다. 당신이 "숨기기"버튼을 클릭하면. 잔액의 총계도 변경됩니다. 따라서 금액을 계산하는 방법에서 '숨기기'옵션을 클릭 할 때마다 ajax 호출을 구현하고 행의 수량을 숨기는 메소드를 사용합니다. –
감사합니다. 내 부분적으로 숨기기 단추에 아약스를 호출해야합니까? –