First of all, I've read all the topics about this issue and couldn't find a solution. Basically I'm trying to apply a simple nested gridview in my MVC project. It all works fine except the expand/collapse function. I implement it with this script:
$(document).ready(function () {
var size = $("#main #gridT > thead > tr > th").size(); // get total column
$("#main #gridT > thead > tr > th").last().remove(); // remove last column header
$("#main #gridT > thead > tr").prepend("<th></th>"); // add one column at first for collapsible column
$("#main #gridT > tbody > tr").each(function (i, el) {
$(this).prepend(
$("<td></td>")
.addClass("hoverEff")
.addClass("expand")
.attr('title', "click for show/hide")
);
//now get sub table from last column and add this to the next new added row
var table = $("table", this).parent().html();
//add new row with this subtable
$(this).after("<tr><td></td><td style='padding:5px; margin:0px;' colspan='" + (size - 1) + "'>" + table + "</td></tr>");
$("table", this).parent().remove();
-->>>Up until this point everything works smoothly.
//// add click event for make collapsible
$(".hoverEff", this).live('click', function () {
alert($(".hoverEff").parent().closest("tr").next().text());
$(".hoverEff").parent().closest("tr").next().slidetoggle(100);
$(".hoverEff").toggleclass("expand collapse");
});
});
//by default make all subgrid in collapse mode
$("#main #gridt > tbody > tr td.expand").each(function (i, el) {
$(this).toggleclass("expand collapse");
$(this).parent().closest("tr").next().slidetoggle(100);
});
});
When I open my page, subgrids are not collapsed, and when I click on the button, it doesn't trigger anything. I tried to check if the function is working with this code:
alert($(".hoverEff").parent().closest("tr").next().text());
and it is. I've also heard that inline elements cannot be affected by a .slidetoggle, but my element is a tr inside a table. I've also heard that .live is deleted in jQuery 2.0.0, but I have jQuery 3.0.0 installed through NuGet. I can't trigger .on('click') event and I'm starting to think I've messed up something in the bundle rendering.
My grid:
<div class="inner" id="inner2">
<div id="main" style="padding:25px; background-color:white;">
#grid.GetHtml(
htmlAttributes: new { id = "gridT", width = "700px" },
columns: grid.Columns(
grid.Column("singleUser.RA_Responsible_Person", "RA Responsible Person"),
grid.Column("singleUser.Issues_Count", "Issues Count"),
grid.Column(header: "Min Deadline", format: (item) => string.Format("{0:dd-MM-yyyy}", item.singleUser.Min_Deadline)),
grid.Column(header: "Max Deadline", format: (item) => string.Format("{0:dd-MM-yyyy}", item.singleUser.Max_Deadline)),
grid.Column(format: (item) =>
{
WebGrid subGrid = new WebGrid(source: item.Cases);
return subGrid.GetHtml(
htmlAttributes: new { id = "subT" },
columns: subGrid.Columns(
subGrid.Column("Issue_ID", "Issue_ID"),
subGrid.Column("Issue", "Issue"),
subGrid.Column("Case_Status", "Case_Status"),
subGrid.Column("Issued_by", "Issued_by"),
subGrid.Column("Issue_Date", "Issue_date"),
)
);
})
)
)
</div>
Please assist! Thanks in advance!
Are there any console errors?
I believe that toggleclass should be toggleClass should it not? The same with slideToggle?
I used google graphs in this page earlier and added jquery as a library through a link to googleapis. I removed it and I think all the functions stopped working, but it's a start.
I'll make another issue with a different content.
Related
i have 2 tables and i need to select some rows from one, then drop them to the other table in the position i want to place.
i can drag multiple rows, but they will be placed on the end of table..i need to place where i want.
i tried with this
$("#table1 .childgrid tr, #table2 .childgrid tr").draggable({
helper: function(){
var selected = $('.childgrid tr.selectedRow');
if (selected.length === 0) {
selected = $(this).addClass('selectedRow');
}
var container = $('<div/>').attr('id', 'draggingContainer');
container.append(selected.clone().removeClass("selectedRow"));
return container;
}
});
http://jsfiddle.net/83k9k/5/
but i can't apply the sortable.
here i tried to apply sortable, but i can't apply the selected rows.
$("#table1 .childgrid, #table2 .childgrid").sortable({
connectWith: ".childgrid",
//connectWith: ".t_sortable",
items: $(".draggable_tr"),
//items: "> tr:not(:first)",
appendTo: $tabs,
//helper:"clone",
zIndex: 999990,
helper: function(){
var selected = $('.childgrid tr.selectedRow');
if (selected.length === 0) {
selected = $(this).toggleClass('selectedRow');
}
console.log(selected.length)
var container = $('<div/>').attr('id', 'draggingContainer');
//console.log(container)
container.append(selected.clone().removeClass("selectedRow"));
return container;
},
update: function (event, ui)
{
$(this).append(ui.helper.children());
$('.selectedRow').remove();
}
}).disableSelection();
http://jsfiddle.net/ce36vd0h/
where is the issue?
Please check below. I have made some changes. THe problem I see is , you are dragging inside a table, so you do not get which tr you are dragging after . I have made below changes. I have added a class tt1 in every table row on the right side table. And then called the droppable in the table row instead of the table itself. You can do the same for the left table. This just show the example. I am not sure if this goes with your actual usecase but I feel this is the best way to identify the table row where you are dropping. I am not sure about the sortable, are you trying to apply sortable after the row is moved ?
http://jsfiddle.net/2gb7vcLf/
$("#table1 .childgrid, #table2 .tt1").droppable({
drop: function (event, ui) {
// alert($(this).hasClass('childgrid'))
//alert($(this).closest('tr').hasClass('draggable_tr'))
var droppedRow = $(this).closest('tr');
// $(droppedRow).css('color', 'red');
$(ui.helper.children()).insertAfter(droppedRow);
// $(droppedRow).next(ui.helper.children());
//$(this).append(ui.helper.children());
$('.selectedRow').remove();
}
});
<tr class="draggable_tr tt1">
So I am trying to add a button two each row in the table.
I was able to accomplished this by doing the code below, but the button keeps generating every time i go to the next page and come back to it. It adds one button to the table every time I go between pages. I dont understand why this happening. Can someone please help me out. Thank you in advance.
$('#displayTable').on('draw.dt', function () {
$('.dataTable > thead > tr').append('<th style="width: 163px"></th>');
//adding button to table.
$('.dataTable > tbody > tr').append('<td>Add to Topic</td>');
});
You may use TableTools extension for DataTables to add custom buttons to table header.
In the override options:
"aButtons": [
{
"sExtends": "text",
"sButtonText": " ",
"fnInit": function ( nButton, oConfig ) {
$(nButton).attr("title", "Delete selected items");
$(nButton).removeClass("DTTT_button").addClass("btn btn-small");
$(nButton).append('<i class="icon-trash"></i> <i class="icon-white icon-exclamation-sign"></i>');
},
"fnClick": function( nButton, oConfig, oFlash ) {
if (!$(nButton).attr('disabled')) {
// code to run on click
deleteSelectedItems();
}
}
}
]
For anyone in the future looking for an answer, this is what I did
<script type="text/javascript">
$('#displayTable').on('preInit.dt', function () {
//adding column to table.
$('.dataTable > thead > tr').append('<th>header</th>');
});
$('#displayTable').on('draw.dt', function () {
//adding button to column.
$('.dataTable > tbody > tr').append('<td>Add to Topic</td>');
});
</script>
I have a grid to which I can dynamically add rows and columns. Each column has a checkbox next to it and checking it makes all checkboxes for that column be selected.
It looks like this:
Below is my code to add columns by clicking the "Add another column" button.
$('#btnAddCol').click(function () {
myfrom.find('tr').each(function(){
var trow = $(this);
var columnName = $('#colorName').val()
if(trow.index() === 1){
trow.append('<th > ' + columnName + ' <input type="checkbox" class="colmaster"/>');
}else if (trow.index() > 1){
trow.append('<td><input type="checkbox" name="'+columnName+'" class="child" /></td>');
}
});
iter += 1;
});
And here is the code for selecting all checkboxes in the column.
$('.colmaster').click(function(){
var idx = $(this).parent().index();
$('#colorgrid td:nth-child(' + (idx + 1) + ') input.child').prop('checked', this.checked);
})
Question
For the newly added columns, justadded in the screenshot above, when I check the checkbox it doesn't seem to select all checkboxes in that column
Here is a working fiddle for everything: http://jsfiddle.net/y55nn1qx/4/
$('.colmaster').click will only bind the event to .colmaster elements that exist at the time of running the code. Try something like this:
$('#colorgrid').on('click', '.colmaster', function() {
// insert your .colmaster.click code here
});
Here's the jQuery API reference for on.
Change $('.colmaster').click(function(){ to:
$('.colmaster').live('click', function(){ // jQuery < 1.7
So that any .colmaster added to the DOM after DOM ready can also be included.
NOTE
If you upgrade to a modern version of jQuery you would use:
$(document).on('click', '.colmaster', function(){ //jQuery 1.7+
jQuery API Documentation | live
I have this function which is responsible of making the table tr and th collapse. But in fact I don't want to collapse all the table columns (th and tr). I think because I am using $('tr th').click(function() so all the tr and th are collapsing. Is there any way I can exclude some columns? I don't want to move the title..
$('tr th').click(function() {
var index = (this.cellIndex + 1);
var cells = $('table tr > :nth-child(' + index + ')');
cells.toggleClass('collapsed');
if ($(this).hasClass('collapsed')) {
$(this).find('span').html('<b>+</b>');
}
else {
$(this).find('span').html('<b>-</b>');
}
if ($('table tr > th:not(.collapsed)').length)
$('table').removeClass('collapsed');
else
$('table').addClass('collapsed');
});
});
Here is my code: jsfiddle.net/9QkVd/20
To exclude the first column (title), you can use:
$('tr th:gt(0)').click(function() {
...
});
Updated fiddle: http://jsfiddle.net/9QkVd/22/
If I'm interpreting your question correctly, you want a function that collapses some headers but not all. See this fiddle.
All you need to do is slightly modify the selector for your .click function:
$('tr th.collapse').click(function() { ... }
and add a class collapsible onto the headers that you want to have this functionality. Change your CSS a bit so that your title isn't so large and you're done!
I am having a table which has fixed header and first 3 columns are fixed .
http://jsfiddle.net/ncUdA/embedded/result/
I want to drag and drop the columns (i.e) A,B,C,D,E,F are columns which should be shiftable (drag and drop) enabled.All the elements below it should also be shifted to the new position.
http://jsfiddle.net/ncUdA/
I found a plugin which does what i want but i was not able to implement because usage of multiple tables in my code for fixed header and fixed 3 columns.
http://johnny.github.com/jquery-sortable/#table
Below code is the plugin code on how to do it.
I am using handlebars for templating.
var oldIndex
$('.sorted_head tr').sortable({
containerSelector: 'tr',
itemSelector: 'th',
placeholder: '<th class="placeholder"/>',
vertical: false,
onDragStart: function (item, group, _super) {
oldIndex = item.index()
item.appendTo(item.parent())
_super(item)
},
onDrop: function (item, container, _super) {
var field,
newIndex = item.index()
if(newIndex != oldIndex)
item.closest('table').find('tbody tr').each(function (i, row) {
row = $(row)
field = row.children().eq(oldIndex)
if(newIndex)
field.before(row.children()[newIndex])
else
row.prepend(field)
})
_super(item)
}
})
After google-ing to find the solution to re-order table columns by using drag'n'drop.
I found that 'akottr' has write an awesome jquery plugin. here
It is a library-independent js-function that gives you the ability to re-order table columns by using drag'n'drop. It's very easy to use.
$('#defaultTable').dragtable();
Thus, I hope you will get the re-order table as you want.
Check it out for more example : http://akottr.github.io/dragtable/