Другой способ сделать это, не используя FasterCSV:
Требуют csv библиотеки рубина в файле инициализатора как config/initializers/dependencies.rb
require "csv"
Как некоторый фон, следующий код базируется прочь Форма Расширенного поиска Ryan Bate , который создает поисковый ресурс. В моем случае выставочный метод поискового ресурса возвратит результаты ранее сохраненного поиска. Это также отвечает на csv и использует шаблон представления для форматирования желаемого вывода.
def show
@advertiser_search = AdvertiserSearch.find(params[:id])
@advertisers = @advertiser_search.search(params[:page])
respond_to do |format|
format.html # show.html.erb
format.csv # show.csv.erb
end
end
show.csv.erb файл похож на следующее:
<%- headers = ["Id", "Name", "Account Number", "Publisher", "Product Name", "Status"] -%>
<%= CSV.generate_line headers %>
<%- @advertiser_search.advertisers.each do |advertiser| -%>
<%- advertiser.subscriptions.each do |subscription| -%>
<%- row = [ advertiser.id,
advertiser.name,
advertiser.external_id,
advertiser.publisher.name,
publisher_product_name(subscription),
subscription.state ] -%>
<%= CSV.generate_line row %>
<%- end -%>
<%- end -%>
На версии HTML страницы отчета у меня есть ссылка для экспорта отчета, что пользователь просматривает. Следующее является link_to, который возвращает csv версию отчета:
<%= link_to "Export Report", formatted_advertiser_search_path(@advertiser_search, :csv) %>
The TreeNode
itself does not have any Enabled
property, so you will need to find some means of tracking that state. One way to do this is to create a new class that inherits TreeNode
and that features an Enabled
property. Another way is to maintain a list of disabled tree nodes.
Once that is done, you can use the ForeColor
property of the TreeNode
to have it appear grayed out (for instance using the SystemColors.GrayText
value).
Finally you can use the BeforeSelect
event to evaluate whether it's OK for the user to select a particular node, and use the Cancel
property of the event args in that event to prevent selecting it if that node is disabled:
private void TreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
e.Cancel = !NodeIsEnabled(e.Node);
}
Two options: