我有下表#physician-privellages
,在该表上已实现DataTable
。
.table
table.table.table-striped#physician-privellages
thead
tr
th First Name
th Last Name
th Email
th Patient Privileges
th Visit Privileges
- if Authorizer.physician_practice?
th My Practice
th Actions
tbody.privileged-physician-records
- user_permissions_for_physicians = physician_privileges_permissions(user_id)
- user_permissions_for_physician = user_permissions_for_physicians[user_id]
- user_permissions_for_physician&.delete(user_id)
- user_permissions_for_physician&.each do |user_id, user_permissions|
tr
td
= "#{user_permissions[:physician].first_name}"
td
= "#{user_permissions[:physician].last_name}"
td
= "#{user_permissions[:physician].email}"
td class="physician_#{user_permissions[:physician].id}"
.patients
= "#{user_permissions[:patient_permissions].first.titleize}"
text = hidden_field_tag 'physicians_privileges[][patients]', user_permissions[:patient_permissions].first
td class="physician_#{user_permissions[:physician].id}"
.visits
= "#{user_permissions[:visit_permissions].first.titleize}"
text = hidden_field_tag 'physicians_privileges[][visits]', user_permissions[:visit_permissions].first
- if Authorizer.physician_practice?
td class="physician_#{user_permissions[:physician].id}"
- if user_permissions[:note_permissions] == []
.practice
| None
text = hidden_field_tag "physicians_privileges[][notes]", ["disable_notes"].first
- else
.practice
= "#{note_permission_translation[user_permissions[:note_permissions].first&.to_sym]}"
text = hidden_field_tag 'physicians_privileges[][notes]', user_permissions[:note_permissions].first
td class="physician_#{user_permissions[:physician].id}"
text = hidden_field_tag 'physicians_privileges[][user_id]', user_permissions[:physician].id, { class: 'user_id' }
.btn-group.btn-group-xs.width-45.inline-flex-end
- if user_permissions_for_physician.present?
button.btn.btn-default.js-load-physician-permissions-modal type="button"
= font_awesome_icon('edit')
- require 'json'
text.hidden = user_permissions.to_json
a.btn.btn-danger.delete-physician-privilege.main-form data-id="#{user_permissions[:physician].id}"
= font_awesome_icon('destroy')
我正在使用CoffeeScript
动态添加一些行,该行将返回以下html.slim
并将其追加到上表中。
- physician_users.each do |physician|
tr
td #{physician.first_name}
td #{physician.last_name}
td #{physician.email}
- if permissions == 'admin'
td class="physician_#{physician.id}"
.patients
| Administer Patients
text = hidden_field_tag 'physicians_privileges[][patients]', 'administer_patients'
td class="physician_#{physician.id}"
.visits
| Administer Visits
text = hidden_field_tag 'physicians_privileges[][visits]', 'administer_visits'
- else
td class="physician_#{physician.id}"
.patients
| View Patients
text = hidden_field_tag 'physicians_privileges[][patients]', 'view_patients'
td class="physician_#{physician.id}"
.visits
| View visits
text = hidden_field_tag 'physicians_privileges[][visits]', 'view_visits'
- if Authorizer.physician_practice?
td class="physician_#{physician.id}"
.practice
| None
text = hidden_field_tag "physicians_privileges[][notes]", 'disable_notes'
td class="physician_#{physician.id}"
text = hidden_field_tag 'physicians_privileges[][user_id]', physician.id
.btn-group.btn-group-xs.width-45.inline-flex-end
button.btn.btn-default.js-load-physician-permissions-modal type="button"
= font_awesome_icon('edit')
text.hidden = {physician: physician}.to_json
a.btn.btn-danger.delete-physician-privilege.main-form data-id="#{physician.id}"
= font_awesome_icon('destroy')
现在的问题是,搜索功能不适用于由html
和js
附加的行。
我已经做了一些Google搜索,并找到了一种在DataTable中包括新行的方法。 Add new row in DataTable
但是,这表明我们只能在table.row.add
中使用参数,并且在某些列中还有一些hidden_fields以及“编辑-删除”按钮。 Moveover我也需要在新行中处理HTML类。
那么有没有办法处理这种情况?
这是我的 AJAX 通话,以添加新行
$.ajax
url: '/organizations/'+org_id+'/members/get_privileged_physicians'
type: 'get'
dataType: 'json'
data: ids: new_selected_user_ids, permissions: permission
success: (data) ->
$('.dataTables_empty').remove()
$('.privileged-physician-records').append data.markup
$('.select_physicians').val('').trigger('chosen:updated')
$('.physicians-priviliges-area .chosen-select').chosen
allow_single_deselect: true
no_results_text: 'No results'
width: '100%'
return
这是我的控制器功能
def get_privileged_physicians
physician_users = User.where(id: params[:ids])
markup = render_to_string(partial: 'auth/members/privileged_physician_users',
locals: { physician_users: physician_users, permissions: params[:permissions] })
render json: { markup: markup }
end