I have a ajax call to fetch data from server for the jqGrid in my rails application.
$(document).ready(function() {
colNamesData = ['Project', 'Activity', 'Description', 'Hours', 'Date','']
colModelData = [
{name:'projects.name',index:'projects.name', width:130, sorttype:"text"},
{name:'creation_date',index:'creation_date', width:130, sorttype:"date"},
{name:'buttons', index:'buttons', width:270, align:'center', search:false}
]
$("#time_sheet_table").jqGrid({
datatype: 'json',
colNames: colNamesData,
colModel: colModelData,
url: 'timesheets/timesheet_index_jqgrid?table_name = timesheet_index_jqgrid&',
mtype: "Get",
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
id: "id",
repeatitems: true,
cell: 'cell',
button: "buttons",
},
Here's my controller code:
if timesheet.deletable?(@user)
@buttons = 1
buttons += "<div style='margin-right:55px'>"
buttons += "<a class='button delete-button' href='#' onclick=\"jQuery('#time_sheet_table').jqGrid('delGridRow', #{timesheet.id}, {});\"><span class='link'>Delete</span></a>" + "</div>"
end
@cell << {
:id => timesheet.id,
:cell => [timesheet.project_name,timesheet.creation_date.strftime("%Y-%m-%d"),buttons]
}
end
list_of_resources = {
"total" => total_page(timesheets.count,grid_id),
"page" => session[:page][:time_sheet_table],
"records" => timesheets.count,
"rows" => @cell
}
I want to access the value of @buttons from controller but unable to guess how to pass and access in my view so that i can put conditions like for ex...
<% if @buttons == 1 %>
colNamesData.splice(1,1);
colModelData.splice(1,1);
<% end %>
thanx