I'm trying to specify a fixed width for a few columns in a jQuery datatable. I've attempted to accomplish this via the column definitions specified in the datatables documentation, but the column and column header still get auto-sized.
Here's the jsFiddle I've been working with: jsFiddle
JavaScript:
var table = $('#example2').DataTable({
"tabIndex": 8,
"dom": '<"fcstTableWrapper"t>lp',
"bFilter": false,
"bAutoWidth": false,
"data": [],
"columnDefs": [
{
"class": 'details-control',
"orderable": false,
"data": null,
"defaultContent": '',
"targets": 0
},
{
"targets": 1},
{
"targets": 2,
"width": "60px"},
{
"targets": 3,
"width": "1100px"},
{
"targets": 4},
{
"targets": "dlySlsFcstDay"},
{
"targets": "dlySlsFcstWkTtl",
"width": "60px"}
],
"order": [
[1, 'asc']
]
});
HTML:
<div class="forecastTableDiv">
<table id="example2" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th colspan="5"></th>
<th class="slsFiscalWk" colspan="8">201424</th>
<th class="slsFiscalWk" colspan="8">201425</th>
<th class="slsFiscalWk" colspan="8">201426</th>
<th class="slsFiscalWk" colspan="8">201427</th>
</tr>
<tr>
<!--<th></th>-->
<!--<th>Vendor</th>-->
<!--<th>Origin ID</th>-->
<!--<th>Destination</th>-->
<!--<th>Vendor Part Nbr</th>-->
<!--<th>SKU</th>-->
<!--<th>Mon</th>-->
<!--<th>Tue</th>-->
<!--<th>Wed</th>-->
<!--<th>Thu</th>-->
<!--<th>Fri</th>-->
<!--<th>Week Ttl</th>-->
<th></th>
<th>Vendor</th>
<th>Origin ID</th>
<th style="width: 200px">Vendor Part Nbr</th>
<th>SKU</th>
<!-- First week -->
<th class="dlySlsFcstDay" >Mon</th>
<th class="dlySlsFcstDay" >Tue</th>
<th class="dlySlsFcstDay" >Wed</th>
<th class="dlySlsFcstDay" >Thu</th>
<th class="dlySlsFcstDay" >Fri</th>
<th class="dlySlsFcstDay" >Sat</th>
<th class="dlySlsFcstDay" >Sun</th>
<th class="dlySlsFcstWkTtl" >Week Ttl</th>
<!-- Second week -->
<th class="dlySlsFcstDay" >Mon</th>
<th class="dlySlsFcstDay" >Tue</th>
<th class="dlySlsFcstDay" >Wed</th>
<th class="dlySlsFcstDay" >Thu</th>
<th class="dlySlsFcstDay" >Fri</th>
<th class="dlySlsFcstDay" >Sat</th>
<th class="dlySlsFcstDay" >Sun</th>
<th class="dlySlsFcstWkTtl" >Week Ttl</th>
<!-- Third week -->
<th class="dlySlsFcstDay" >Mon</th>
<th class="dlySlsFcstDay" >Tue</th>
<th class="dlySlsFcstDay" >Wed</th>
<th class="dlySlsFcstDay" >Thu</th>
<th class="dlySlsFcstDay" >Fri</th>
<th class="dlySlsFcstDay" >Sat</th>
<th class="dlySlsFcstDay" >Sun</th>
<th class="dlySlsFcstWkTtl" >Week Ttl</th>
<!-- Fourth and final week -->
<th class="dlySlsFcstDay" >Mon</th>
<th class="dlySlsFcstDay" >Tue</th>
<th class="dlySlsFcstDay" >Wed</th>
<th class="dlySlsFcstDay" >Thu</th>
<th class="dlySlsFcstDay" >Fri</th>
<th class="dlySlsFcstDay" >Sat</th>
<th class="dlySlsFcstDay" >Sun</th>
<th class="dlySlsFcstWkTtl" >Week Ttl</th>
</tr>
</thead>
<tfoot>
</table>
</div>
When I inspect the live code, I can see that the width I'm specifying in the column definition is getting added to the column as a style attribute, but it doesn't match the actual width of the column.
This is not a DataTables issue. See how column widths are determined. Based on this algorithm I see the following two solutions.
Solution 1
Calculate yourself the table width and set it accordingly.
#example {
width: 3562px;
}
See live example here: http://jsfiddle.net/cdog/jsf6cg6L/.
Solution 2
Set the minimum content width (MCW) of each cell and let the user agent to determine the column widths.
To do this, add classes to the target columns to be able to style them:
var table = $('#example').DataTable({
tabIndex: 8,
dom: '<"fcstTableWrapper"t>lp',
bFilter: false,
bAutoWidth: false,
data: [],
columnDefs: [{
class: 'details-control',
orderable: false,
data: null,
defaultContent: '',
targets: 0
}, {
targets: 1
}, {
class: 'col-2',
targets: 2
}, {
class: 'col-3',
targets: 3
}, {
targets: 4
}, {
targets: 'dlySlsFcstDay'
}, {
targets: 'dlySlsFcstWkTtl'
}],
order: [[1, 'asc']]
});
Then set the desired value of the minimum width property for each class:
.col-2,
.dlySlsFcstWkTtl {
min-width: 60px;
}
.col-3 {
min-width: 1100px;
}
See live example here: http://jsfiddle.net/cdog/hag7Lpm5/.
Here is a code sample (fixed the column width for 4 column table):
set autoWidth: false;
set px values to first 3 columns;
important: check if the table width is a bit more than 3 columns + final one;
adjust the table width and 4th column.
$('#example').DataTable({ //four column table
autoWidth: false, //step 1
columnDefs: [
{ width: '300px', targets: 0 }, //step 2, column 1 out of 4
{ width: '300px', targets: 1 }, //step 2, column 2 out of 4
{ width: '300px', targets: 2 } //step 2, column 3 out of 4
]
});
Set table width, 4*300px:
#example { width: 1200px };
As result you will see 1st 3 columns with 300px width and the final one will be flexible and about 150px (which requires additional adjusting).
Last but not least: fixed column size 300px will not prevent you from the case when cell contains a too long (> 300px without spaces) word. So you have to keep in mind that all words must be less than the fixed side of your column.
for the <table> tag or its css class or css id add the following style:
`table{
margin: 0 auto;
width: 100%;
clear: both;
border-collapse: collapse;
table-layout: fixed;
word-wrap:break-word;
}`
Setting a fixed column width can be a real pain. The following solution works nicely.
{ width: 250, targets: 1, class: "someClass",
render : function ( data, type, row ) {
if ( type === 'display' ) {
return `<div style="width:250px"> ${data} </div>`;
}
return data;
}
}
Related
I have an issue and want to see if this thought is possible. I created a project tracker where an individuals can load their project information (office, project title, status, date, assigned to., etc). The form works great. I have another form, update form, for the individual to update their input value (choice same as load project form: office, project, title, status, date, assigned to., etc) as the project progress. This form updates great. However, a issue I am having, if the HTML field is left blank, on the update form HTML input field, it sends a value of “null” that overrides the value posted to the tracker list of post - not being updated. The update form intended purpose is to give the individual a list of possible choices to what they might need to update, in this case everything.
Is there a way to not send any value if the input field is left blank to not override the value currently posted? Is this even possible or do I need to do something different, like have a separate update form for each different area/column being updated.
I am posting and updating the values to a SharePoint using the REST API.
---Edit to include Script---
<div id="container">
<!-- --------------- code to update a list item ------------- -->
<div id="updateForm">
<div id="UpdateClose" style='text-align: left; float: right; margin-right: 10px; cursor: pointer;'>Close</div>
<div style='margin: 0 auto; width: 100%; padding-top: 5px; padding-bottom: 5px; color: white; margin-top: 40px; margin-bottom: 10px; background-color: orange;'>
<p>Click here to move</p>
</div>
<p>Fill out this form completely to update your item.</p>
<input placeholder="Item ID" type="text" id="itemID">
<table>
<tr>
<td>Office</td>
<td><input type="text" id="uOffice" style="width: 200px"></td>
</tr>
<tr>
<td>Project Title</td>
<td><input type="text" id="uProjectTitle" style="width: 200px"></td>
</tr>
<tr>
<td>Priority</td>
<td><input type="text" id="uPriority" style="width: 200px"></td>
</tr>
<tr>
<td>Start Date</td>
<td><input type="text" id="uStartDate" style="width: 200px"></td>
</tr>
<tr>
<td>Assigned To</td>
<td><input type="text" id="uAssignedTo" style="width: 200px"></td>
</tr>
<tr>
<td>Status</td>
<td><input type="text" id="uStatus" style="width: 200px"></td>
</tr>
<tr>
<td>Requestor</td>
<td><input type="text" id="uRequestor" style="width: 200px"></td>
</tr>
</table>
<button id="UpdateListItem">UPDATE</button>
</div>
<div id="introTxt">
<p>Post and Track your Projects</p>
<p id='openForm'><img class='qIcon' src="https://intelshare.intelink.gov/sites/dcsa/ep/epMainFiles/Project_Tracker/graphics/google-docs.svg" alt="logo" style="width: 100px; position: relative; top: 0px; margin-right: 10px; cursor: pointer; "><span style='color: blue; cursor: pointer; position: relative; top: 20px; font-weight: bold;' >Select to post a project. When the post project form opens, hover over the input fields for additional instructions.</span></p>
<p id='openUForm'><img class='qIcon' src="https://intelshare.intelink.gov/sites/dcsa/ep/epMainFiles/Project_Tracker/graphics/google-docs.svg" alt="logo" style="width: 100px; position: relative; top: 0px; margin-right: 10px; cursor: pointer; "><span style='color: black; cursor: pointer; position: relative; top: 20px; font-weight: bold;' >Select to update a task. When the post project form opens, hover over the input fields for additional instructions.</span></p>
</div>
<div id="qForm" style='width: 250px; height: auto; padding: 10px; position: absolute; z-index: 10; background-color: white; border: 1px solid grey; text-align:center; cursor: all-scroll; display: none;'>
<div id="qFormClose" style='text-align: left; float: right; margin-right: 10px; cursor: pointer;'>Close</div>
<div style='margin: 0 auto; width: 100%; padding-top: 5px; padding-bottom: 5px; color: white; margin-top: 40px; margin-bottom: 10px; background-color: orange;'>
<p>Click here to move</p>
</div>
<input type="text" placeholder="Enter Your Office" name="Office" id="office" title='Enter in your office' required> <br><br>
<input type="text" placeholder="Enter a Project Name" name="Project Name" id="project" title='Enter in a project name' required> <br><br>
<input type="text" placeholder="Priority" name="url" id="priority" title='Enter in project priority'> <br><br>
<input type="text" placeholder="Project Start Date" name="Start Date" id="startDate" title='Enter in project start date'> <br><br>
<input type="text" placeholder="Assigned to" name="Assigned" id="assigned" title='Project assigned to'> <br><br>
<input type="text" placeholder="Status" name="Status" id="status" title='Project status'> <br><br>
<input type="text" placeholder="Requestor" name="Requestor" id="requestor" title='Project requestor'> <br><br><br>
<div id="udList" style='cursor: pointer';>Submit</div>
</div>
<div class="row vertical-padding"></div>
<!--Close of vertical padding-->
<div id="leftCol" class="grid_12">
<input id="myInput" type="text" placeholder="To find a specific task, enter either the office name, individual's name, or by task ID...">
<h2 style='color:blue; marigin: 0 auto; text-align: center; font-weight: bold;'>Project List</h2>
<p>Select table header to sort.</p>
<div id="CustomerPanel">
<table id='tableCars' style="width: 100%;" border="1 px">
<tr>
<td>
<div id="carsGrid" style="width: 100%"></div>
</td>
</tr>
</table>
</div>
</div>
<!--Close of grid-->
</div>
<!--Close container-->
/*Add to Project Tracker List*/
var context;
var web;
var Url;
var listItemEntity;
jQuery(document).ready(function() {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', FunctionReady);
ItemSubmit();
$("#qForm").draggable();
$("#qFormClose").click(function() {
$("#qForm").fadeOut();
});
$("#openForm").click(function() {
$("#qForm").fadeIn();
});
$("#openUForm").click(function() {
$("#updateForm").fadeIn();
});
}); //Close of document ready function
var answer = document.getElementById('comAnswer');
function ItemSubmit() {
$("#udList").click(function() {
$("#qForm").fadeOut(400);
var officeValue = $("#office").val();
var projectValue = $("#project").val();
var priorityValue = $("#priority").val();
var startDateValue = $("#startDate").val();
var assignedValue = $("#assigned").val();
var statusValue = $("#status").val();
var requestorValue = $("#requestor").val();
if (this.value != 0) {
AddItemToList(listItemEntity, officeValue, projectValue, priorityValue, startDateValue, assignedValue, statusValue, requestorValue);
} else {
AddItemToList(listItemEntity, officeValue, projectValue, priorityValue, startDateValue, assignedValue, statusValue, requestorValue);
}
$('#qForm').children('input').val('');
});
}
function FunctionReady() {
context = new SP.ClientContext.get_current();
web = context.get_web();
context.load(web);
context.executeQueryAsync(onRequestSuccess, onRequestFailure);
}
function onRequestSuccess() {
Url = web.get_url();
GetListItemEntity(Url);
}
function onRequestFailure(sender, args) {
alert("Error Occured:" + args.get_message());
}
function GetListItemEntity(webUrl) {
var queryUrl = webUrl + "/_api/lists/getbytitle('ProjectTracker')?$select=ListItemEntityTypeFullName";
$.ajax({
url: queryUrl,
method: "GET",
headers: {
"Accept": "application/json;odata=verbose"
},
success: onEntitySuccess,
error: onEntityFailure
});
}
function onEntitySuccess(data) {
listItemEntity = data.d.ListItemEntityTypeFullName;
}
function onEntityFailure(err) {
alert(err.statusText);
}
function AddItemToList(r, officeValue, projectValue, priorityValue, startDateValue, assignedValue, statusValue, requestorValue) {
try {
var queryUrl = Url + "/_api/lists/GetByTitle('ProjectTracker')/items?";
$.ajax({
url: queryUrl,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({
'__metadata': {
'type': r
},
'Office': officeValue,
'ProjectTitle': projectValue,
'Priority': priorityValue,
'StartDate': startDateValue,
'AssignedTo': assignedValue,
'Status': statusValue,
'Requestor': requestorValue
}),
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: onQuerySucess,
error: onQueryFailure
});
} catch (ex) {
alert("Exception" + ex.message);
}
}
function onQuerySucess() {
jQuery("#success").fadeIn();
}
function onQueryFailure(error) {
alert(JSON.stringify(error));
}
jQuery(document).ready(function() {
////Project Tracker Table script
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ProjectTracker')/items";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept": "application/json; odata=verbose"
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
var objItems = data.d.results;
var tableContent = '<table id="projectTable" style="width:100%" border="1 px"><thead><th>ID</th>' + '<th>Office</th>' + '<th>Project_Title</th>' + '<th>Project_Priority</th>' + '<th>Project_Date</th>' + '<th>Assigned_To</th>' + '<th>Project_Status</th>' + '<th>Requestor</th>' + '</thead><tbody>';
for (var i = 0; i < objItems.length; i++) {
tableContent += '<tr class="sortTable">';
tableContent += '<td>' + objItems[i].ID + '</td>';
tableContent += '<td>' + objItems[i].Office + '</td>';
tableContent += '<td>' + objItems[i].ProjectTitle + '</td>';
tableContent += '<td>' + objItems[i].Priority + '</td>';
tableContent += '<td>' + objItems[i].StartDate + '</td>';
tableContent += '<td>' + objItems[i].AssignedTo + '</td>';
tableContent += '<td>' + objItems[i].Status + '</td>';
tableContent += '<td>' + objItems[i].Requestor + '</td>';
tableContent += '</tr>';
}
$('#projectGrid').append(tableContent);
}
function onError(error) {
alert('Error');
}
}); ///End of Document Ready Function
///Sort Project Table
jQuery(document).ready(function() {
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$(".sortTable").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
jQuery(document).on("click", 'th', function() {
if ($(this).is('.asc')) {
$(this).removeClass('asc');
$(this).addClass('desc selected');
sortOrder = -1;
} else {
$(this).addClass('asc selected');
$(this).removeClass('desc');
sortOrder = 1;
}
var table = $(this).parents('table').eq(0)
var rows = table.find('tr:gt(0)').toArray().sort(comparer($(this).index()))
this.asc = !this.asc
if (!this.asc) {
rows = rows.reverse()
}
for (var i = 0; i < rows.length; i++) {
table.append(rows[i])
}
})
}); //close of document ready
//Update Project Tracker list item Script
$(document).ready(function() {
jQuery(document).on("click", '#UpdateListItem', function() {
updateListItem();
}); //button closed
jQuery(document).on("click", '#UpdateClose', function() {
$("#updateForm").fadeOut();
}); //button closed
function updateListItem() {
//var listName = "ProjectTracker";
var url = _spPageContextInfo.webAbsoluteUrl;
var myID = $("#itemID").val();
var listName = "ProjectTracker";
var office = $("#uOffice").val();
var pTitle = $("#uProjectTitle").val();
var priority = $("#uPriority").val();
var startDate = $("#uStartDate").val();
var assignedTo = $("#uAssignedTo").val();
var status = $("#uStatus").val();
var requestor = $("#uRequestor").val();
var title = "New Updated Information";
var itemType = "SP.Data.Project_x0020_TrackerListItem";
console.log(office);
var item = {
"__metadata": {
"type": itemType
},
"Title": title,
"Office": office,
"ProjectTitle": pTitle,
"Priority": priority,
"StartDate": startDate,
"AssignedTo": assignedTo,
"Status": status,
"Requestor": requestor
};
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ProjectTracker')/items(" + myID + ")",
type: "POST",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": "*"
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
jQuery("#success").fadeIn();
}
function onError(error) {
alert(JSON.stringify(error));
}
} //Function close
});
I have a table with tbody and using Vuejs:
<tbody>
<tr v-for="(item,i) in data" :key="i">
<th scope="row"></th>
<td>{{item.dwg}}</td>
<td>{{item.name}}</td>
<td>{{item.ValueOfDay1}}</td>
<td>{{item.ValueOfDay2}}</td>
<td>{{item.ValueOfDay3}}</td>
</tr>
</tbody>
I want to use v-if to change the styling of the <td> element:
if item.ValueOfDay1 = 10 --> background-color of <td> is red,
if item.ValueOfDay1 = 10.1 --> background-color of <td> is blue,
if item.ValueOfDay1 = 10.2 --> background-color of <td> is green.
How can I do this?
This is resolution for your problem, I hope that help you
https://jsfiddle.net/mathmelo/fjs9x7by/3/#
HTML
<table>
<tbody>
...
<td :class="changeBackgroundColor(item.ValueOfDay1)" >{{item.ValueOfDay1}}</td>
...
</tr>
</tbody>
Vue
new Vue({
el: '#app',
data: {
data: [
{dwg: 0, name: 'test' , ValueOfDay1: 10, ValueOfDay2: 20, ValueOfDay3: 30},
{dwg: 0, name: 'test2' , ValueOfDay1: 10.2, ValueOfDay2: 20, ValueOfDay3: 30},
{dwg: 0, name: 'test3' , ValueOfDay1: 10.1, ValueOfDay2: 20, ValueOfDay3: 30}
]
},
methods: {
changeBackgroundColor(valueOfDay) {
//Get the decimal part of the number
decimals = valueOfDay - Math.floor(valueOfDay);
switch(decimals.toFixed(1)){
case '0.0' : return 'red'
case '0.1' : return 'blue'
case '0.2' : return 'green'
}
}
}
});
And CSS
.red {
background-color: red;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
Adding dynamic styling based on condition as below->
:class="item.ValueOfDay1 == 10 ? 'bgRed' : item.ValueOfDay1 == 10.1 ? 'bgBlue' : item.ValueOfDay1 == 10.2 ? 'bgGreen' : ''"
<tbody>
<tr v-for="(item,i) in data" :key="i">
<th scope="row"></th>
<td>{{item.dwg}}</td>
<td>{{item.name}}</td>
<td :class="item.ValueOfDay1 == 10 ? 'bgRed' : item.ValueOfDay1 == 10.1 ? 'bgBlue' : item.ValueOfDay1 == 10.2 ? 'bgGreen' : ''">{{item.ValueOfDay1}}</td>
<td :class="item.ValueOfDay1 == 10 ? 'bgRed' : item.ValueOfDay1 == 10.1 ? 'bgBlue' : item.ValueOfDay1 == 10.2 ? 'bgGreen' : ''">{{item.ValueOfDay2}}</td>
<td :class="item.ValueOfDay1 == 10 ? 'bgRed' : item.ValueOfDay1 == 10.1 ? 'bgBlue' : item.ValueOfDay1 == 10.2 ? 'bgGreen' : ''">{{item.ValueOfDay3}}</td>
</tr>
</tbody>
CSS
.bgRed{
background:red;
}
.bgBlue{
background:blue;
}
.bgGreen{
background:green;
}
I need to add a background color that should be like this
I think that the only solution would be to add a span inside the th container like this:
<th class="sorting_asc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Companies: activate to sort column descending" aria-sort="ascending">
<span>Companies</span>
</th>
Unfortunatly I have no idea of how to add the spans
Add this bgcolor attribute in <th> like this:
<th bgcolor="#FF0000">Companies</th>
You can include <span>'s in the columns / columnDefs title option :
$('#example').DataTable( {
columns: [
{ data: "name", title: '<span class="red">Name</span>' },
{ data: "position", title: '<span class="blue">Position</span>' },
//etc
]
})
examples -> http://jsfiddle.net/z1afh42j/
Need help in removing sort arrows (asc and desc) on data tables header row, then when the user click the header column an ascending arrow will appear and of course data will be sorted in asc order
$("#MyDataTable").dataTable({
"aoColumns": [{"bSortable": false}, null]
});
"aoColumnDefs": [ { "bSortable": false, "aTargets": [ 1, 3 ] } ]
To remove sort arrows from the second and the fourth columns.
Reference: http://wordpress.org/support/topic/plugin-wp-table-reloaded-removing-the-updown-sorting-arrows-on-specific-columns
> This is Best Answer for removing sort arrow
>
>
> $('#itjbg-table').dataTable({
> 'columnDefs': [{ 'orderable': false, 'targets': 0 }], // hide sort icon on header of first column
> 'aaSorting': [[1, 'asc']] // start to sort data in second column });
Within dataTables.Bootstrap.css are three classes that add these sort images. They are sorting, sorting_asc, and sorting_desc. During the DataTable initialization disable sorting as first stated by "satej kumar sahu" via the bSortable : false. Then do a removeClass for the header, my header had an id="division". Then create a click event for the header, same id, to do a another removeClass to preserve any other functionality, in my case to preserve the column dropdown via columnFilter. Review attached code.
$('#example').dataTable({
"order": [[1, "asc"], [7, "asc"], [4, "asc"]],
"aoColumnDefs": [{ "bSortable": false, "aTargets": [1]}],
"columns":[null, {className: ""}, null, null, null , null, null, null, null, null]
}).columnFilter({
sPlaceHolder: "head:after",
aoColumns: [null, { type: "select" }, null,
null, null, null, null, null, null, null]
});
$('#division').removeClass('sorting sorting_asc sorting_desc');
$('#division').click(function () {
$('#division').removeClass('sorting sorting_asc sorting_desc');
});
table.dataTable thead .sorting { background: url('../images/sort_both.png') no-repeat center right; }
table.dataTable thead .sorting_asc { background: url('../images/sort_asc.png') no-repeat center right; }
table.dataTable thead .sorting_desc { background: url('../images/sort_desc.png') no-repeat center right; }
<thead>
<tr class="info">
<th scope="col">Title</th>
<th id="division" scope="col">Division</th>
<th scope="col">Attendee</th>
<th scope="col">Supervisor</th>
<th scope="col">Start Date</th>
<th scope="col">End Date</th>
<th scope="col">Duration(hr)</th>
<th scope="col">Fee</th>
<th scope="col">Status</th>
<th scope="col">Comments</th>
</tr>
</thead>
HOW TO REMOVE DATATABLES GLYPHCONS / ICONS !!
Use this following code on your css file :
if you see the column glyph-cons on Table header use this !!
th.sorting_asc::after, th.sorting_desc::after { content:"" !important; }
if you see the glyph-cons on Table data use this !!
td.sorting_asc::after, td.sorting_desc::after { content:"" !important; }
in short change "this" part, where the class="sorting_desc/asc" situated.
"this".sorting_asc::after, "this".sorting_desc::after { content:"" !important; }
what I got from your question is that you want to remove initial sort from the table and only sort when the user clicks on a column header. you can do that using the following code:
$(document).ready( function() {
$('#example').dataTable( {
"aaSorting": []
} );
} );
http://datatables.net/ref#aaSorting
I've already searched for the answer, and there are a few for this type of issue but not that I can get to work. What I am trying to setup is probably best explained if you use the code below and try it yourself, but I'll try to explain myself.
I have several input fields which are cloned after they have data inputted into them. Now I am trying to integrate an autocomplete script with it. So that all the one has to do is type the name of a person, select it from the popup and it puts the data into the cells.
The issue is that it won't input data for anything but the initial row, because the cloner changes the id by increasing the id number everything its cloned. Can anyone point me in the right direction of how to increment the autocompleter? Or how to rerun for each clone?
Thanks everyone, and here are the files needed to replicate the issue.
SQL
-- Table structure for table `employees`
--
CREATE TABLE IF NOT EXISTS `employees` (
`id` int(12) NOT NULL AUTO_INCREMENT,
`fname` varchar(50) NOT NULL,
`lname` varchar(50) NOT NULL,
`wage` int(12) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `employees`
--
INSERT INTO `employees` (`id`, `fname`, `lname`, `wage`) VALUES
(1, 'John', 'Doe', 25),
(2, 'Bob', 'Smith', 30);
test.php
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
//cloning script
$("#employee input").live("keyup", function(){
var id = this.id.match(/\d+/);
});
// The second requirement:
var uniqueIds = $("#employee tr").length;
$("#employee input[id^='employee_fname']").live("change", function(){
var $thisRow = $(this).closest("tr"),
$clone = $thisRow.clone(true), // Clone row
$inputs = $clone.find("input").val("");// Reset values, return all inputs
uniqueIds++; //Increment ID
$inputs[0].id = "employee_id" + uniqueIds;
$inputs[1].id = "employee_fname" + uniqueIds;
$inputs[1].id = "employee_lname" + uniqueIds;
$inputs[2].id = "employee_wage" + uniqueIds;
//$inputs.eq(0).focus(); // Focus on the first text field
$thisRow.after($clone); // Add row after current one
});
</script>
<script>
//autosuggest script
function lookup(employee_fname) {
if(employee_fname.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("test_ac.php", {queryString: ""+employee_fname+""},function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup
function fill1(thisValue) {
$('#employee_fname').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
function fill2(thisValue) {
$('#employee_id').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
function fill3(thisValue) {
$('#employee_lname').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
function fill4(thisValue) {
$('#employee_wage').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
</script>
<style>
.suggestionsBox {
position: relative;
left: 30px;
margin-top:100px;
margin-left:-35px;
margin-right:0px;
margin-bottom:0px;
padding:0px;
width: 150px;
background-color: #212427;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #659CD8;
}
</style>
</head>
<body>
<table>
<tr>
<td width="200">
<div class="suggestionsBox" id="suggestions" style="display: none;">
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>
</td>
<td>
<table>
<tr>
<td width="120" align="left" style="width:120px;">ID</td>
<td width="120" align="left" style="width:120px;">First Name</td>
<td width="120" align="left" style="width:120px;">Last Name</td>
<td width="120" align="left" style="width:120px;">Wage</td>
</tr>
</table>
<table id="employee">
<tr>
<td align="left"><input type="text" id="employee_id" name="employee_id" style="width:100px; background-color:#e5e5e5;" readonly="readonly" onblur="fill2();"/></td>
<td align="left"><input type="text" id="employee_fname" name="employee_fname" style="width:100px;" onblur="fill1();" onkeyup="lookup(this.value);"/></td>
<td align="left"><input type="text" id="employee_lname" name="employee_lname" style="width:100px; background-color:#e5e5e5;" readonly="readonly" onBlur="fill3"/></td>
<td align="left"><input type="text" id="employee_wage" name="employee_wage" style="width:100px; background-color:#e5e5e5;" readonly="readonly" onblur="fill4();" /></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
test_ac.php
<?php
// PHP5 Implementation - uses MySQLi.
// mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase');
$db = new mysqli('localhost', 'root' ,'passsword', 'database');
if(!$db) {
// Show error if we cannot connect.
echo 'ERROR: Could not connect to the database.';
} else {
// Is there a posted query string?
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
// Run the query: We use LIKE '$queryString%'
// The percentage sign is a wild-card, in my example of countries it works like this...
// $queryString = 'Uni';
// Returned data = 'United States, United Kindom';
// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10
$query = $db->query("SELECT fname, lname, id, wage FROM employees WHERE fname LIKE '$queryString%' LIMIT 10");
if($query) {
// While there are results loop through them - fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using <li> for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
echo '<li onClick="fill1(\''.$result->fname.'\');
fill2(\''.$result->id.'\');
fill3(\''.$result->lname.'\');
fill4(\''.$result->wage.'\');
">'.$result->lname. ',' .$result->fname.'</li>';
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
}
?>
Change the autosuggest script to the code below. This solved my issue.
var sourceElement;
//autosuggest script
function lookup2(source, employee_id) {
sourceElement = source;
if(employee_id.length == 0) {
// Hide the suggestion box.
$('#suggestions2').hide();
} else {
$.post("../../autocomplete/jobadd_employee.php", {queryString: ""+employee_id+""},function(data){
if(data.length >0) {
$('#suggestions2').show();
$('#autoSuggestionsList2').html(data);
}
});
}
} // lookup
function fill8(thisValue) {
$('#employee_id'+sourceElement.id.replace("employee_id","")).val(thisValue);
setTimeout("$('#suggestions2').hide();", 200);
}
function fill9(thisValue) {
$('#employee_fname'+sourceElement.id.replace("employee_id","")).val(thisValue);
setTimeout("$('#suggestions2').hide();", 200);
}
function fill10(thisValue) {
$('#employee_lname'+sourceElement.id.replace("employee_id","")).val(thisValue);
setTimeout("$('#suggestions2').hide();", 200);
}
function fill11(thisValue) {
$('#employee_wage'+sourceElement.id.replace("employee_id","")).val(thisValue);
setTimeout("$('#suggestions2').hide();", 200);
}