Jquery ui theme overwriting datatables css - css

I can't figure out why my jquery ui themeroller won't play nice with my datatables I'm trying to include in a dialog. The datatable uses the jquery-ui color and the columns are not readable. Am I missing something?
Here is my HTMl:
<div id="dvAdvanced" class="display" style="padding-top:40px;">
<table id="tblAdvSearch">
<thead>
<tr>
<th>Drawing #</th>
<th>Project</th>
<th>Customer</th>
<th>Created By</th>
<th>Date Created</th>
</tr>
</thead>
<tbody>
<tr>
<td>1#Html.DisplayFor(model => model.PartNumber)</td>
<td>2#Html.DisplayFor(model => model.RFQ)</td>
<td>3#Html.DisplayFor(model => model.customer_id)</td>
<td>#Html.DisplayFor(model => model.CreatedBy)</td>
<td>#Html.DisplayFor(model => model.DateCreated)</td>
</tr>
</tbody>
</table>
</div>
Here is my javascript:
$(document).ready(function () {
$("#btnAdvSearch").button();
$("#btnGenPart").button();
dlgAdvSearch = $("#dlgAdvSearch").dialog({
"jQueryUI": true,
title: "Advanced Search",
autoOpen: false,
height: 500,
width: 900,
modal: true,
buttons: {
Close: function () {
dlgAdvSearch.dialog("close");
}
}
});
$("#tabs").tabs();
$("#tblQuickSearch").dataTable();
$("#tblAdvSearch").dataTable();
$("#btnAdvSearch").button().on("click", function () {
dlgAdvSearch.dialog("open");
});;
});
And finally here is my bundleconfig:
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/jquery-ui.min.css",
"~/Content/jquery-ui.structure.min.css",
"~/Content/jquery-ui.theme.min.css",
"~/Content//DataTables/css/jquery.dataTables.css",
"~/Content//DataTables/css/dataTables.jqueryui.css",
"~/Content/DataTables/css/jquery.dataTables_themeroller.css",
"~/Content/DataTables/css/dataTables.bootstrap.css"));

Related

Gutenberg removing table tag on save

I am attempting to create a Gutenberg block to track exercise sets. I'm using a RichText component to allow users to edit default values in a table I pre-populate for them.
The block works well on the editor and, after saving, renders correctly in the post. However, when I reload the editor, I receive this error message: Block validation: Expected tag name 'thead', instead saw 'table'. It's almost like Gutenberg is stripping the table tag but leaving everything else.
Of course, that doesn't make sense, but I'm not sure what else it could be.
Here's my code, heavily edited for readability:
const { registerBlockType } = wp.blocks;
const { AlignmentToolbar, BlockAlignmentToolbar, BlockControls, RichText, useInnerBlockProps } = wp.blockEditor;
const { Component } = wp.element;
registerBlockType('bsd-strong-post/training-session', {
title: __('Strong Post', 'bsd-strong-post'),
description: __('Provides a short summary of a training session', 'bsd-strong-post'),
category: 'common',
icon: blockIcons.weight_lifting,
keywords: [
__('strength workout', 'bsd-strong-post'),
__('strong', 'bsd-strong-post'),
__('training', 'bsd-strong-post')
],
supports: {
html: true
},
attributes: {
/* ... */,
dayTemplateContent: {
type: 'string',
source: 'html',
selector: '.bsd-strong-post-training-template'
},
/* ... */
},
/* ... */
edit: class extends Component {
constructor(props) {
super(...arguments);
this.props = props;
/* ... */
this.dayTemplateHandler = this.dayTemplateHandler.bind(this);
this.onChangeBlockTemplate = this.onChangeBlockTemplate.bind(this);
}
/* ... */
dayTemplateHandler(new_val) {
const dayTemplateList = this.state.dayTemplateList;
let selectedDayTemplate = dayTemplateList.filter(item => {
return item.value == new_val;
})
if (selectedDayTemplate[0]['label']) {
this.props.setAttributes({
dayTemplateId: new_val,
dayTemplateName: selectedDayTemplate[0]['label']
});
}
this.getTemplate(new_val);
}
getTemplate(templateId) {
api.getDayTemplate(templateId)
.then((data) => {
if (!data.status || data.status == 0) {
return false;
};
if (!data.day_template) {
return false;
};
this.props.setAttributes({
dayTemplateContent: data.day_template.template_content
});
return data.day_template;
}).catch((err) => {
console.log('getTemplate caught error')
return false;
});
}
onChangeBlockTemplate(value) {
this.props.setAttributes({
dayTemplateContent: value
});
}
/* ... */
render() {
const { dayTemplateHandler, onChangeBlockTemplate, phaseControlHandler, programControlHandler, updateBlockAlignment, updateTextAlignment } = this;
const { block_alignment, dayTemplateId, dayTemplateName, dayTemplateContent, phaseId, phaseName, programAuthor, programId, programName, programPhases, text_alignment } = this.props.attributes;
/* ... */
return [
<InspectorControls>
<PanelBody title={ __('Basics', 'bsd-strong-post') }>
<SelectControl
label={ __('Day', 'bsd-strong-post') }
help={ __('The training session (e.g., Day One)', 'bsd-strong-post') }
value={ dayTemplateId }
options={ this.state.phaseTemplates }
onChange={ dayTemplateHandler }
/>
}
</PanelBody>
</InspectorControls>,
<div className='bsd-strong-post-block-editor'>
<div className={ this.props.className }>
<RichText
placeholder={ __('Log your lifts here') }
value={ dayTemplateContent }
multiline={ false }
onChange={ onChangeBlockTemplate }
className='bsd-strong-post-training-log'
/>
</div>
</div>
];
}
},
save: (props) => {
return (
<div className={ `align${props.attributes.block_alignment}` }>
<ul className='list-unstyled'style={{ textAlign: props.attributes.text_alignment }}>
<li>
<strong>{ __('Program', 'bsd-strong-post') }: </strong>
<span className='bsd-strong-post-program'>{ props.attributes.programName }</span>
</li>
<li>
<strong>{ __('Phase', 'bsd-strong-post') }: </strong>
<span className='bsd-strong-post-phase-ph'>{ props.attributes.phaseName }</span>
</li>
<li>
<strong>{ __('Day', 'bsd-strong-post') }: </strong>
<span className='bsd-strong-post-day-ph'>{ props.attributes.dayTemplateName }</span>
</li>
<li>
<strong>{ __('Author', 'bsd-strong-post') }: </strong>
<span className='bsd-strong-post-author-ph'>{ props.attributes.programAuthor }</span>
</li>
</ul>
<RichText.Content
value={ props.attributes.dayTemplateContent }
className='bsd-strong-post-training-log'
/>
</div>
)
}
});
Here's the console output on reload:
Content generated by 'save' function:
<div class="wp-block-bsd-strong-post-training-session alignwide"><ul class="list-unstyled"><li><strong>Program: </strong><span class="bsd-strong-post-program">Madcow</span></li><li><strong>Phase: </strong><span class="bsd-strong-post-phase-ph">Intermediate</span></li><li><strong>Day: </strong><span class="bsd-strong-post-day-ph">Day 1</span></li><li><strong>Author: </strong><span class="bsd-strong-post-author-ph">Madcow</span></li></ul>
<thead>
<tr>
<th scope="col">Exercise</th>
<th scope="col">Set 1</th>
<th scope="col">Set 2</th>
</tr>
</thead>
<tbody>
<tr class="bsd-strong-post-exercise-one">
<td class="bsd-strong-post-exercise-name">Squat</td>
<td class="bsd-strong-post-set-1">95 x 5</td>
<td class="bsd-strong-post-set-2">135 x 5</td>
</tr>
</tbody>
</div>
Content retrieved from post body:
<div class="wp-block-bsd-strong-post-training-session alignwide"><ul class="list-unstyled"><li><strong>Program: </strong><span class="bsd-strong-post-program">Madcow</span></li><li><strong>Phase: </strong><span class="bsd-strong-post-phase-ph">Intermediate</span></li><li><strong>Day: </strong><span class="bsd-strong-post-day-ph">Day 1</span></li><li><strong>Author: </strong><span class="bsd-strong-post-author-ph">Madcow</span></li></ul><table class='bsd-strong-post-training-template'>
<thead>
<tr>
<th scope='col'>Exercise</th>
<th scope='col'>Set 1</th>
<th scope='col'>Set 2</th>
</tr>
</thead>
<tbody>
<tr class='bsd-strong-post-exercise-one'>
<td class='bsd-strong-post-exercise-name'>Squat</td>
<td class='bsd-strong-post-set-1'>95 x 5</td>
<td class='bsd-strong-post-set-2'>135 x 5</td>
</tr>
</tbody>
</table></div>
I can see that the content displayed below Content generated by 'save' function: is missing the <table> and </table> tags. I've tried to work around this by adding tagName='table' in the RichText.Content properties inside the save function, but then the console shows duplicate <table> and </table> tags.
EDIT: The table is populated when a user makes a change to the Select control in InspectorControls. This action calls dayTemplateHandler, which among other things, calls getTemplate, a function that gets the content of the table from the database. Here's an example of that output (data.day_template.template_content):
<table class='bsd-strong-post-training-template'>
<thead>
<tr>
<th scope='col'>Exercise</th>
<th scope='col'>Set 1</th>
<th scope='col'>Set 2</th>
</tr>
</thead>
<tbody>
<tr class='bsd-strong-post-exercise-one'>
<td class='bsd-strong-post-exercise-name'>Squat</td>
<td class='bsd-strong-post-set-1'>95 x 5</td>
<td class='bsd-strong-post-set-2'>135 x 5</td>
</tr>
</tbody>
</table>
On reviewing the table template and considering the error, I suspect the issue is the selector of the dayTemplateContent attribute, .bsd-strong-post-training-template
The first time the content is saved, it successfully loads the template data from database and saves the complete table structure. When the content is reloaded, the block validator fails as the selector of dayTemplateContent reads in the child nodes of the table's css selector (which is thead) and doesn't match expected content. Ref: HTML example of blockquote/paragraphs
Try wrapping the <table> template with a <div class="bsd-strong-post-training-template"> or changing the selector.

Styling material ui table cells according to their values

I have a material ui table and I would like to colour the different cells according to what value is displayed in them. The cells are populated with json data using map. For example if a cell has the value 1, I would like the colour to be yellow.
{
Name: "A Person",
Attendence: [
{
date: "2019/12/01",
attendence: 1
},
{
date: "2019/12/02",
attendence: 1
},
{
date: "2019/12/03",
attendence: 0
}
]
}
];
return (
<Fragment>
{attendence.map(person => {
return (
<Table>
<thead>
<tr>
<th>Name</th>
{person.Attendence.map(personAttendendance => {
return <th>{personAttendendance.date}</th>;
})}
</tr>
</thead>
<tbody>
<tr>
<td>{person.Name}</td>
{person.Attendence.map(personAttendendance => {
return <td>{personAttendendance.attendence}</td>;
})}
</tr>
</tbody>
</Table>
);
})}
</Fragment>
);
}
export default Test;
That is what the table looks like. I tried
if(value === 1){
return(
<TableCell style={{ background: "red" }}>{value}</TableCell>
)
} else {
return(
<TableCell style={{ background: "red" }}>{value}</TableCell>
)
}
}
But that did not work . It just read the else and made everything red.
Change your tbody in test.js to:
<tbody>
<tr>
<td>{person.Name}</td>
{person.Attendence.map(personAttendendance => {
if(personAttendendance.attendence === 1){
return <td style={{background: "red" }}>{personAttendendance.attendence}</td>;
} else {
return <td style={{background: "blue" }}>{personAttendendance.attendence}</td>;
}
})}
</tr>
</tbody>
or
<tbody>
<tr>
<td>{person.Name}</td>
{person.Attendence.map(personAttendendance => {
return <td style={{background: personAttendendance.attendence === 1 ? "red" : "blue"}}>{personAttendendance.attendence}</td>;
})}
</tr>
</tbody>
Which ever suits you best.
Link to fork here. (using the second example)

TH in Semantic Datatable inside tab width is not set

How to make tag is width to 100% in Semantic css with datatable inside tab.
Currently I have 3 tab with 1 datatable each, width is only set on Tab1 but not in Tab2 and Tab3
Here is my code: 1. HTML
<div class="ui top attached tabular menu">
<a data-toggle="tab" class="item active" data-tab="first">Other Hardwares Relation</a>
<a data-toggle="tab" class="item" data-tab="second">Software and License Relation</a>
<a data-toggle="tab" class="item" data-tab="third">Document Relation</a>
</div>
<div class="ui bottom attached tab segment active" data-tab="first">
<table class="ui celled table display nowrap" style="width:100%" datatable>
...
</table>
</div>
<div class="ui bottom attached tab segment" data-tab="second">
<table class="ui celled table display nowrap" style="width:100%" datatable>
<thead>
<tr>
<th>No.</th>
<th>Software #</th>
...
</tr>
</thead>
<tbody>
#foreach ($softwares as $index=>$software)
<tr>
<td>{{ $index+1 }}</td>
<td>{{$software->code}}</td>
...
</tr>
#endforeach
</tbody>
</table>
</div>
<div class="ui bottom attached tab segment" data-tab="third">
<table class="ui celled table display nowrap" style="width:100%" datatable>
...
</table>
</div>
</div>
and 2. JS
<script>
$(document).ready(function() {
$('[datatable]').DataTable({
"scrollX": true,
"paging": false,
"searching": false,
dom: 'Bfrtip',
buttons: [ ... ]
});
$('.menu .item').tab();
});
</script>
The best practice in Datatables is instead of bringing your data with foreach you should try datatables builtin ajax. I've faced same problem and solved by turning my data form to json with and made an ajax call.
PHP JSON Encode;
$object = (object) $arr;
echo json_encode($object);
Datatables Ajax Form;
var table = $('#example').DataTable({
fixedHeader: true,
"initComplete": function(){
$('.ui.loader').remove();
)
},
ajax: {
url: 'api/yourhandler.php',
type: 'GET',
data: {
searchTerm:searchTerm,
'pane':paneno,
project: projectFilter
},
},
order: [[ 0, "desc" ], [ 5, "asc" ]],
columnDefs: [
{ "searchable": true, "targets": [0,1,2,3,4,5] },
{ "className": "align-center", "targets": [0,2,3,4,5,6,7,8,9] },
{ "width": "1%", "targets": [2,3,4,5,6,7] },
{ "width": "10%", "targets": [8] },
{ "width": "25%", "targets": [1,9] }
],
columns: [
{ data: "columndata1" },
{ data: "columndata2" },
{ data: "columndata3" },
{ data: "columndata4" }
],
responsive: true,
paging: true,
pageLength: 25
});
If you choose not to make an ajax, I could say your problem cause is your data is not fit with the table. Try to focus your foreach, you will see the problem.

asp.net mvc javascript Hide table row by default if model bool property is false

I added a javascript to hide tablerow if the user click on a toggle radio button.
<script type="text/javascript">
$(document).ready(function () {
$('#radio1').change(function () {
if ($(this).val() == false) {
$('#trMyTextBox').show();
}
});
$('#radio2').change(function () {
if ($(this).val() == false) {
$('#trMyTextBox').hide();
}
});
});
</script>
<tr id="trMyTextBox">
<td style="width: 50%;">
</td>
<td>
<div class="col-xs-7">
#Html.TextBoxFor(model => model.MyTextBox, new {#id = "textEmail", #class = "form-control"})
</div>
</td>
</tr>
I got it working when the user is clicking between the radio buttons. I need to make a change, from my controller, I am passing in model and if the properties like showtextbox is false, I need to hide the table row by default. How do I do that? Thanks.
This should do it.
<tr style="display: #(!Model.ShowTextbox ?Html.Raw("none;") :Html.Raw(""))"><td>A</td></tr>
A more clean solution is to not use the inline styles, but use a css class based on your Model property value.
<tr class="#(Model.ShowTextbox ? Html.Raw("show") : Html.Raw("hide"))"><td>A</td></tr>
And your css classes would be
.show
{
display: block;
}
.hide
{
display:none;
}
#code
var style = "display: none;";
if(Model.ShowTableRow)
{
style = "";
}
end code
<tr id="trMyTextBox" style="#style">
Set the style display as none will hide the row and it's contents by default unless ShowTableRow is true then no hidden display attribute will be applied.

Fixing table header on webpage

I would like to know how to fix a table header even if we scroll down on a website and out of the table view.
I would like to use css style to do this. Thank you.
I would also like to know how to fix an element on a webpage so it always appears even when we scroll down. The image can be text. Use div and css
You would do something like this by tapping into the scroll event handler on window, and using another table with a fixed position to show the header at the top of the page.
Example:
var tableOffset = $("#table-1").offset().top;
var $header = $("#table-1 > thead").clone();
var $fixedHeader = $("#header-fixed").append($header);
$(window).bind("scroll", function() {
var offset = $(this).scrollTop();
if (offset >= tableOffset && $fixedHeader.is(":hidden")) {
$fixedHeader.show();
}
else if (offset < tableOffset) {
$fixedHeader.hide();
}
});
body { height: 1000px; }
#header-fixed {
position: fixed;
top: 0px; display:none;
background-color:white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="table-1">
<thead>
<tr>
<th>Header1</th>
<th>Header2</th>
<th>Header3</th>
</tr>
</thead>
<tbody>
<tr>
<td>info</td>
<td>info</td>
<td>info</td>
</tr>
<tr>
<td>info</td>
<td>info</td>
<td>info</td>
</tr>
<tr>
<td>info</td>
<td>info</td>
<td>info</td>
</tr>
</tbody>
</table>
<table id="header-fixed"></table>
Taken from an old post of mine, here's an example of both things that you want done together in one fiddle.
JSFiddle
JQuery:
function moveScroll() {
var scroll = $('#table-container').offset().top;
var anchor_top = $("#maintable").offset().top;
var anchor_bottom = $("#bottom_anchor").offset().top;
if (scroll > anchor_top && scroll < anchor_bottom) {
clone_table = $("#clone");
if (clone_table.length === 0) {
clone_table = $("#maintable").clone();
clone_table.attr({
id: "clone"
}).css({
position: "fixed",
"pointer-events": "none",
left: $("#maintable").offset().left + 'px',
top: 130
}).width($("#maintable").width());
$("#table-container").append(clone_table);
$("#clone").width($("#maintable").width());
$("#clone thead").css({
visibility: "true"
});
$("#clone tbody").css({
visibility: "hidden"
});
var footEl = $("#clone tfoot");
if (footEl.length) {
footEl.css({
visibility: "hidden"
});
}
}
} else {
$("#clone").remove();
}
}
$('#table-container').scroll(moveScroll);

Resources