Width issue from http://datatables.net/ - css

Using a data table from http://datatables.net/ , How can i stop it from overflowing on the page?
EDIT:
<script type="text/javascript">
$(document).ready(function() {
$('#comment').dataTable( {
"oLanguage": {
"sInfo": "",
"sInfoEmpty": "",
"sInfoFiltered": ""
},
"sPaginationType": "full_numbers",
"iDisplayLength": 5,
"bLengthChange": false,
"aaSorting": [[3, 'desc']],
"aoColumns": [
{ "bSortable": false },
null,
null,
{ "asSorting": [ "desc" ] },
null,
{ "bSortable": false }
] } );
});
</script>
<table id="comment">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Comment</th>
<th>Created</th>
<th>Attachments</th>
<th><center>Delete?</center></th>
</tr>
</thead>
<tbody>
<% #company.comments.each do |comment| %>
<tr>
<td>
<% if comment.user.avatar.blank? %>
<%= image_tag("default_user.png", :height => "50", :width => "50") %>
<% else %>
<%= image_tag(comment.user.avatar_url, :height => "50", :width => "50") %>
<% end %>
</td>
<% if comment.user.name.nil? %>
<td><%= comment.user.email %></td>
<% else %>
<td><%= comment.user.name %></td>
<% end %>
<td><%=raw comment.body %></td>
<td><%= comment.created_at.to_s(:db) %></td>
<% if comment.file.blank? %>
<td></td>
<% else %>
<td><%= link_to comment.file_identifier, comment.file_url %></td>
<% end %>
<td><center><%= link_to image_tag("delete.png", :alt => "Delete", :height => "15px"), [comment.company, comment], :confirm => 'Are you sure?', :method => :delete %></center></td>
</tr>
<% end %>
</tbody>
</table>

The DataTables function won't help with trouble-shooting. It's a CSS issue. And also a content issue. First the content:
Sizing on tables is "fuzzy"; the table will do its best to size to your suggestions, and will exactly match your suggestions when it can. When you have a huge long string, though (I believe I'm seeing a whole long series of A's and D's, right?) it has no choice. It will make the column as wide as it needs to be to fit the content. The other columns will then be as narrow as they can be and still accomodate your content.
The solution? CSS. It boils down to overflow: hidden. In your stylesheet, set your TD elements to use overflow: hidden and the string will get "chopped off". This isn't always visually pleasing, but sometimes web development is about compromise.
One of those compromises is to also set text-overflow: ellipsis. Any text that can't fit into the cell will be truncated and the ellipsis symbol (three tightly-kerned dots; it's a single character, not three actual dots) will be inserted at the end where it gets cut off.
But then how do you see the data in its entirety? Tricky one. I've just been running a script in the fnRowCallback callback that sets the title of the cell to be the same as its contents. Then on mouseover, a tooltip shows you the content. I'm sure there are better ways.
In the end, what you need to ask is: is a super-long string like that even realistic? What's the expected content?

http://datatables.net/styling/ids_classes has a list of the classes/ids applied - can't you just set a width on the wrapper element?

Apply custom width, e.g.:
.dataTables_wrapper {width:60%}

Related

PaperClip ruby on rails inconsistent image sizing on upload

I am using PaperClip in ruby on rails to handle image uploading for a model. It is working well apart from an inconsistent handling of image sizes.
See this example:
See how the picture on the far right is larger than the pictures in the middle and on the left?
I need to identify why this is happening.
This is my development paperclip configuration:
#Paperclip storage locally and specify location of imagemagick
Paperclip.options[:command_path] = "/usr/local/bin/"
PAPERCLIP_STORAGE_OPTS = {
:styles => { :thumb => '100x100#', :medium => '450x300>', :large => '600x400>'},
:convert_options => { :all => '-quality 100' },
:processor => [ :cropper ]
}
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
And I am showing these images using the following bit of code:
<div class="container">
<% count = 0 %>
<% results.each do |event| %>
<% if count == 3 %>
<div class="row"></div>
<% end %>
<div class="col-xs-12 col-md-4">
<ul class="deals">
<li class="impression">
<%= link_to(event) do %>
<%= image_tag event.logo.url(:medium) %>
<div>
<h2><%= event.className %></h2>
<div><%= event.company_name %></div>
<table>
<tbody>
<tr>
<td>
<span>£<%= event.ppt %></span>
£<%= event.ppc %></td>
<td>4 bought</td>
</tr>
</tbody>
</table>
</div>
<% end %>
</li>
</ul>
</div>
<% count = count +1 %>
<% end %>
</div>
When I investigate the actual img sizes after the HTML is rendered they are as follows:
Tennis pic : 334 x 209 (Original image size is 1024 x 640)
Computer Training pic : 334 x 209 (Original image size is 1600 x 1000)
Zumba pic : 334 x 223 (Original image size is 1280 x 854)
For some reason the Zumba picture is 14 pixels longer than the others?! Why is this happening - why is Paperclip not resizing consistently in this configuration? Or is it to do with the css for the page?!
The answer was to ignore the aspect ratio in imagemagick as per :
http://www.imagemagick.org/Usage/resize/#noaspect
I therefore changed the configuration options to be :
#Paperclip storage locally and specify location of imagemagick
Paperclip.options[:command_path] = "/usr/local/bin/"
PAPERCLIP_STORAGE_OPTS = {
:styles => { :thumb => '100x100!#', :medium => '450x300!>', :large => '600x400!>'},
:convert_options => { :all => '-quality 100' },
:processor => [ :cropper ]
}
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
Note the ! in the '100x100!#' which has been added - this is what tells imagemagick to ignore the aspect ratio - which was the reason I was having inconsistently sized images before I added the !.
Wahoo. ! .

Rails - using CSS on some condition

I have a requirement to make a app that has a view. In that view I need to check a condition and if it is true, then need to color a table row appropriately. The easiest way to do this is just to use different header in the view. But how to do it if I want to keep all my styling information in CSS?
If it's just a row you want to colour then you can do it in the view, no need to mess around with headers:
<tr class="<%= "blue" if some_condition %>">
<td>Your text</td>
</tr>
Or:
<% if some_condition %>
<tr class="blue">
<% else %>
<tr class="red">
<% end %>
<td>Your text</td>
</tr>
application_helper.rb
def my_color_for(condition)
if condition
'white'
else
'blue'
end
end
view.haml
- #array.each do |a|
%tr{class: my_color_for(a.value)}

IE7 and CSS display properties

Here is some asp.net markup:
<tr style="display:none" id="AllInRateRow">
<td id="td6">
All-In Fixed Rate <span id="allInRateHelp" />
</td>
<td id="td7">
<%= Html.TextBoxFor(m => m.FixedRate, new { #class = "economicTextBox", propertyName = "FixedRate", dontRegisterNewIndication = true })%> %
</td>
</tr>
<tr style="display:none" id="ProfitRow">
<td id="td93">
Your Swap Profit
</td>
<td id="yourSwapProfit">
<%= Html.TextBoxFor(m => m.Fees.ProfitAmount, new { #class = "economicTextBox", propertyName = "Fees.ProfitAmount", dontRegisterNewIndication = true })%>
<%= Html.RadioButtonFor(m => m.Fees.ProfitType, (int)Chatham.Enumerations.IndicationProfitType.bps,
new { label = "bps", propertyName = "Fees.ProfitType", dontRegisterNewIndication = true })%>
bps
<%= Html.RadioButtonFor(m => m.Fees.ProfitType, (int)Chatham.Enumerations.IndicationProfitType.CurrencyAmount,
new { label = "$", propertyName = "Fees.ProfitType", dontRegisterNewIndication = true })%>
$
</td>
</tr>
I think it's a problem with the display property for CSS. It doesn't display them on page load which is the correct thing, but then the selection of this is supposed to change that:
<td id="td4">
Options <span id="solverHelper" />
</td>
<td id="solveType">
<%=Html.DropDownListFor(m => m.Fees.CalculationSource, DropDownData.SolverOptionsList(),
new { propertyName = "Fees.CalculationSource", dontRegisterNewIndication = true })%>
</td>
And those things happen through JQuery setting CSS and changing it like so:
var pricingOptions = $("#Fees_CalculationSource").val();
if(pricingOptions == <%= ((int)Chatham.Web.Models.Indications.SwapModel.SolverOptions.AllInRate).ToString() %>)
{
$("#AllInRateRow").css("display", "none");
$("#ProfitRow").css("display", "table-row");
if(canExcludeFees) $("#IncludeFeesOption").css("display", "table-row");
else $("#IncludeFeesOption").css("display", "none");
}
else if (pricingOptions == <%= ((int)Chatham.Web.Models.Indications.SwapModel.SolverOptions.Profit).ToString() %>)
{
$("#AllInRateRow").css("display", "table-row");
$("#ProfitRow").css("display", "none");
$("#IncludeFeesOption").css("display", "table-row");
if(canExcludeFees) $("#IncludeFeesOption").css("display", "table-row");
else $("#IncludeFeesOption").css("display", "none");
}
else if (pricingOptions == <%= ((int)Chatham.Web.Models.Indications.SwapModel.SolverOptions.None).ToString() %>)
{
$("#AllInRateRow").css("display", "table-row");
$("#ProfitRow").css("display", "none");
$('input[propertyname=Fees.IncludeFeeIndicator]:eq(1)').attr('checked', 'checked');
$(
"#IncludeFeesOption").css("display", "none");
}
I think IE7 is unable to work with setting the CSS to the table-row property, but it does work with the 'none'.
Am I correct? And if I am, what would be a workaround?
If I recall correctly IE7 uses display:block. The easiest way to show the elements would be to just call the show/hide methods from jQuery instead of trying to control the display property yourself.
$("#AllInRateRow").show();
$("#ProfitRow").hide();
This will work in all browsers and you will not need to worry about browser specifics.

How can I handle a dynamically created form submit?

How to handle dynamically generated form submit in asp.net mvc?
Form is dynamically created (number, order and type of elements are always different) and i have to handle it (store the data in the database) in the Controller of asp.net mvc (there is no viewstate). Type of input can be everything; hidden fields, radio buttons, check boxes, text inputs etc..
<% using (Html.BeginForm("AddAnswer","Research")){ %>
<%= Html.Hidden("page", ViewData["curentPage"]) %>
<% foreach (var item in Model){ %>
<span><%= Html.Encode(item.Text) %></span>
<%= Html.ActionLink("Edit", "Edit", new {id=item.QuestionID}) %>
|
<%= Html.ActionLink("Details", "Details", new { id=item.QuestionID })%>
<%switch (item.QuestionTipe.QuestionTipeID){
case 4:%>
<table>
<%foreach (var offeredAnswer in item.OfferedAnswer) {%>
<tr>
<td><%= Html.CheckBox("q" + item.QuestionID, false, new{ value = offeredAnswer.Number})%></td>
<td><%= offeredAnswer.Text%></td>
</tr>
<%}%>
</table>
<% break;
case 1:%>
<table>
<% foreach (var offeredAnswer in item.OfferedAnswer) {%>
<tr>
<td><%= Html.RadioButton("q" + item.QuestionID, false, new{ value = offeredAnswer.Number})%></td>
<td><%= offeredAnswer.Text%></td>
</tr>
<%}%>
</table>
<% break;
case 2:%>
<div style="width:220px; height:20px; padding-top:10px; padding-left:8px;">
<%= Html.TextBox("q" + item.QuestionID, null, new { style = "width:200px;"})%>
</div>
<% break;
case 3:%>
<div style="width:220px;height:20px; padding-top:10px;padding-left:8px;">
<div id="q<%= item.QuestionID %>" style="width:200px;" class="slider">
</div>
<%= Html.Hidden("q" + item.QuestionID, 0)%>
</div>
<% break;
}%>
<%}%>
<p>
<input type="submit" value="Sljedeća strana" />
</p>
<%}%>
In your action method, you can access FormCollection parameter, from there, you can access all your passed in values from your submit action.
public ActionResult YourActionMethod(FormCollection form)
{
}
In order to best help you decide how to process the form, it may be helpful to have some additional information.
Something is making the decision to generate this form, what is doing that? What is it basing its rendering on?
Are there known variations of the form that can be accounted for, or are the elements truly independent of each other?
Are each of the elements themselves known? If so, is it possible to give them a consistent id/name so that they may be recognized on the server-side?
When you speak of "handling" the submission, what is the end goal that you'd like to achieve? For example, are you parsing the form to store in a database?
foreach (var key in form.AllKeys) {
var answers = form.GetValues(key);
if (answers.Count() > 1){
foreach (var value in answers)
{
...
}
}
else
{
...
}
}
This is very simple. I'm checking if there is multiple values for some of the answers in the form.

Export HTML Table to Excel

I have HTML table on the ASP.NET MVC View page. Now I have to export this table to Excel.
(1) I have used partial view (Inquiries.ascx) to display the table data from database (using LINQ to Entity)
(2) I also have used UITableFilter plugin to filter the records (Ex: http://gregweber.info/projects/demo/flavorzoom.html )
(3) At any point of time, I have to filter the visible records to Excel.
Appreciate your responses.
Thanks
Rita
Here is my View:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mvc.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content2" ContentPlaceHolderID="cphHead" runat="server">
<script src="../../Scripts/jquery.tablesorter.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.uitablefilter.js" type="text/javascript"></script>
<script type="text/javascript">
//Load Partial View
$('#MyInquiries').load('/Home/Inquiries');
// To Apply Filter Expression using uiTableFilter plugin
$("#searchName").keyup(function() {
$.uiTableFilter($("#tblRefRequests"), this.value);
$("#tblRefRequests").tablesorter({ widthFixed: true, widgets: ['zebra'] });
});
//Export the HTML table contents to Excel
$('#export').click(function() {
//Code goes here
});
</script>
</asp:Content>
//Main Content
<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server">
<h2 class="pageName">View All Inquiries</h2>
<input type="submit" value="Export to Excel" id="export" />
<div id='MyInquiries'></div>
</asp:Content>
Strongly Typed Partial view user control (Inquiries.ascx) to generate table:
<table>
<tr><td valign ="middle">Filter Expression: <%= Html.TextBox("searchName")%></td></tr>
</table>
<table id="tblRefRequests" >
<thead>
<tr>
<th>Tx_ID</th>
<th>TX Date</th>
<th>Name</th>
<th>Email Address </th>
<th>Products</th>
<th>Document Name</th>
</tr>
</thead>
<tbody>
<% foreach (var item in Model) { %>
<tr>
<td visible =false><%= item.RequestID %></td>
<td><%= String.Format("{0:d}", item.RequestDate) %></td>
<td><%= item.CustomerName %></td>
<td><%= Html.Encode(item.Email) %></td>
<td><%= item.ProductName %></td>
<td><%= Html.Encode(item.DocDescription)%></td>
</tr>
<% } %>
</tbody>
</table>
Here is my Controller code to load the Inquiries partial view:
[HttpGet]
public PartialViewResult Inquiries()
{
var model = from i in myEntity.Inquiries
where i.User_Id == 5
orderby i.TX_Id descending
select new {
RequestID = i.TX_Id,
CustomerName = i.CustomerMaster.FirstName,
RequestDate = i.RequestDate,
Email = i.CustomerMaster.MS_Id,
DocDescription = i.Document.Description,
ProductName = i.Product.Name
};
return PartialView(model);
}
Try the jQuery plugin: table2csv. Use the argument, delivery:'value', to return the csv as a string.
Here is an implementation:
Add a regular html input button and a .NET HiddenField to the page
Add an onclick event to that button called "Export"
Create a javascript function, Export, that stores the return value of table2CSV() into the hidden field, and posts back.
The server receives the hiddenfield post data (the csv as a string)
The server outputs the string to the browser as a csv file
.
// javascript
function Export()
{
$('#yourHiddenFieldId').val() = $('#yourTable').table2CSV({delivery:'value'});
__doPostBack('#yourExportBtnId', '');
}
// c#
if(Page.IsPostBack)
{
if(!String.IsNullOrEmpty(Request.Form[yourHiddenField.UniqueId]))
{
Response.Clear();
Response.ContentType = "text/csv";
Response.AddHeader("Content-Disposition", "attachment; filename=TheReport.csv");
Response.Flush();
Response.Write(Request.Form[yourHiddenField.UniqueID]);
Response.End();
}
}
download components:npm install table-to-excel
https://github.com/ecofe/tabletoexcel
var tableToExcel=new TableToExcel();
document.getElementById('button1').onclick=function(){
tableToExcel.render("table");
};
document.getElementById('button2').onclick=function(){
var arr=[
['LastName','Sales','Country','Quarter'],
['Smith','23','UK','Qtr 3'],
['Johnson','14808','USA','Qtr 4']
]
tableToExcel.render(arr,[{text:"create",bg:"#000",color:"#fff"},{text:"createcreate",bg:"#ddd",color:"#fff"}]);
};

Resources