I am using datatables and I have like 20 columns. I tried to force scrolling horizontal but it is not working and it tries to draw the table without scroll in a single page without the scroll bar.
How can this be done?
I have (I removed already some columns):
activitiesTable = $('#activitiesTable').DataTable({
scrollX: true,
ScrollXInner: "200%",
ajax: {
url: "{!! route('listOfActivitiesPerUserAjax') !!}",
type: "POST",
},
columns: [
{ name: 'manager_id', data: 'manager_id' },
{ name: 'manager_name', data: 'manager_name', width: '150px' },
{ name: 'user_id', data: 'user_id' },
{ name: 'user_name', data: 'user_name' , width: '150px'},
{ name: 'project_id', data: 'project_id' },
{ name: 'project_name', data: 'project_name' },
{ name: 'year', data: 'year' },
{ name: 'jan_com', data: 'jan_com', width: '30px', searchable: false },
{ name: 'jan_otl', data: 'jan_otl', width: '10px', searchable: false },
{ name: 'feb_com', data: 'feb_com', width: '30px', searchable: false },
{ name: 'feb_otl', data: 'feb_otl', width: '10px', searchable: false },
{ name: 'mar_com', data: 'mar_com', width: '30px', searchable: false },
{ name: 'mar_otl', data: 'mar_otl', width: '10px', searchable: false },
{ name: 'apr_com', data: 'apr_com', width: '30px', searchable: false },
{ name: 'apr_otl', data: 'apr_otl', width: '10px', searchable: false },
{ name: 'may_com', data: 'may_com', width: '30px', searchable: false },
{ name: 'may_otl', data: 'may_otl', width: '10px', searchable: false },
{ name: 'jun_com', data: 'jun_com', width: '30px', searchable: false },
{ name: 'jun_otl', data: 'jun_otl', width: '10px', searchable: false },
{ name: 'jul_com', data: 'jul_com', width: '30px', searchable: false },
{ name: 'jul_otl', data: 'jul_otl', width: '10px', searchable: false },
{ name: 'aug_com', data: 'aug_com', width: '30px', searchable: false },
{ name: 'aug_otl', data: 'aug_otl', width: '10px', searchable: false },
{ name: 'sep_com', data: 'sep_com', width: '30px', searchable: false },
{ name: 'sep_otl', data: 'sep_otl', width: '10px', searchable: false },
{ name: 'oct_com', data: 'oct_com', width: '30px', searchable: false },
{ name: 'oct_otl', data: 'oct_otl', width: '10px', searchable: false },
{ name: 'nov_com', data: 'nov_com', width: '30px', searchable: false },
{ name: 'nov_otl', data: 'nov_otl', width: '10px', searchable: false },
{ name: 'dec_com', data: 'dec_com', width: '30px', searchable: false },
{ name: 'dec_otl', data: 'dec_otl', width: '10px', searchable: false }
],
columnDefs: [
{
"targets": [0,2,4,6], "visible": false, "searchable": false
}
],
order: [[2, 'asc']],
initComplete: function () {
var columns = this.api().init().columns;
this.api().columns().every(function () {
var column = this;
// this will get us the index of the column
index = column[0][0];
//console.log(columns[index].searchable);
// Now we need to skip the column if it is not searchable and we return true, meaning we go to next iteration
if (columns[index].searchable == false) {
return true;
}
else {
var input = document.createElement("input");
$(input).appendTo($(column.footer()).empty())
.on('keyup change', function () {
column.search($(this).val(), false, false, true).draw();
});
}
});
}
});
Yes, the docs is a bit vague on this point. ScrollXInner (i.e sScrollXInner) was a legacy <1.10.x option no longer supported. In 1.10.x you must either :
Wrap the table into an element with a fixed width
<div style="width: 500px;">
<table id="example"></table>
</div>
http://jsfiddle.net/Lyje8wat/
or (less pretty) set the width of the .dataTables_wrapper element :
div.dataTables_wrapper {
width: 500px;
}
http://jsfiddle.net/s7hdqw29/
In both cases you will neeed to set scrollX :
var table = $('#example').dataTable({
scrollX: true,
...
})
Related
I'm attempting to export the chart as a picture. I just joined eCharts. Can someone explain how the export button operates? I need to download charts as image.
Here's what I try : Do I have something wrong?
<template>
<b-card title="Data Science">
<app-echart-bar:option-data="option"/>
</b-card>
</template>
<script>
import { BCard } from 'bootstrap-vue'
import AppEchartBar from '#core/components/charts/echart/AppEchartBar.vue'
export default {
components: {
BCard,
AppEchartBar,
},
data() {
return {
option: {
toolbox: {
show: true,
orient: 'vertical',
left: 'right',
top: 'center',
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
magicType: { show: true, type: ['line', 'bar', 'stack'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
xAxis: [
{
type: 'category',
data: ['FB', 'IN', 'TW', 'YT',],
},
],
yAxis: [
{
type: 'value',
splitLine: { show: false },
},
],
grid: {
left: '40px',
right: '30px',
bottom: '30px',
},
series: [
{
name: 'Available',
type: 'bar',
barGap: 0,
emphasis: {
focus: 'series'
},
data: [22, 24, 20, 18]
},
{
name: 'Not Available',
type: 'bar',
barGap: 0,
emphasis: {
focus: 'series'
},
data: [12, 10, 14, 16]
},
],
},
}
},
}
</script>
Comp:
<template>
<e-charts
ref="line"
autoresize
:options="option"
theme="theme-color"
auto-resize/>
<script>
import ECharts from 'vue-echarts'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/legend'
import 'echarts/lib/chart/bar'
import theme from './theme.json'
ECharts.registerTheme('theme-color', theme)
export default { components: {
ECharts,
}, props: {
optionData: {
type: Object,
default: null,
}, }, data() {
return {
option: {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
toolbox: {
show: true,
orient: 'vertical',
left: 'right',
top: 'center',
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
magicType: { show: true, type: ['line', 'bar', 'stack'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
legend: {
left: 0,
},
grid: this.optionData.grid,
xAxis: this.optionData.xAxis,
yAxis: this.optionData.yAxis,
series: this.optionData.series,
},
} }, }
</script>
The chart created by eCharts is shown below :
Can somebody assist me with adding a button or tell me whether I need to add a script to download an image.
I am creating simple bar chart using Chartjs in Vue
<bar-chart
:data="[40, 19, 3, 5,]"
:labels="['0-30 days', '31-60 days', '61-90 days', '90+']"
:colors="['blue', 'blue', 'blue', 'blue']"
></bar-chart>
and the code for this is
createChart(chartData: object) {
const canvas = document.getElementById('bar') as HTMLCanvasElement;
const myopt = {
deferred: {
xOffset: '50%',
delay: 250,
},
plugins: {
datalabels: {
align: 'top',
anchor: 'end',
color: 'blue',
},
},
legend: {
display: true,
},
title: {
display: true,
text: 'Chart.js - Different Bar Colors',
},
tooltips: { enabled: true },
responsive: true,
hover: { mode: null },
elements: {
point: {
radius: 0,
},
},
scales: {
xAxes: [{
scaleLabel: {
display: true,
labelString: '',
},
offset: false,
color: 'rgba(0, 0, 0, 0)',
gridLines: {
drawOnChartArea: false,
},
}],
yAxes: [{
id: 'y-axis-0',
mirror: false,
stacked: true,
offset: false,
callback(label:any, index:any, labels:[]) {
return `${label}%`;
},
ticks: {
beginAtZero: true,
min: 0,
},
gridLines: {
display: true,
color: 'rgba(0, 0, 0, 0)',
drawOnChartArea: false,
},
}],
},
};
const options = {
type: 'bar',
data: chartData,
options: myopt,
};
new Chart(canvas, options);
}
the chart which this is generating is not equidistant sharing image for reference
position and width of the bar is incorrect and also I want to know if there is any way by which i can customize labels for y axis e.g. instead of 40,35,30... it will be ** 40k,35k,30k** in y axis
If any one has worked on this case please help
You can make use of the tick callback for your K at the end (https://www.chartjs.org/docs/latest/axes/labelling.html#creating-custom-tick-formats)
var ctx2 = document.getElementById("stack-chart");
var stackChart1 = new Chart(ctx2, {
type: 'bar',
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
callback: (val) => (val + 'k')
}
}]
},
legend: {
display: false,
labels: {
fontSize: 20,
fontColor: '#595d6e',
}
},
tooltips: {
enabled: false
}
},
data: {
labels: ['1', '2', '3', '4', '5'],
datasets: [{
backgroundColor: "#5e63b4",
data: [20, 30, 40, 50, 60]
}]
},
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<canvas id="stack-chart" width="1360" height="450"></canvas>
To Start, here is my ComboBoxItem field
{
name: "State",
type: "ComboBoxItem",
canEdit: true,
valueMap: {
WI: "Wisconsin",
IL: "Illinois",
MN: "Minnesota",
MI: "Michigan"
},
addUnknownValues: false,
allowEmptyValue: false,
completeOnTab: true
}
I'm getting very different behavior out of a ComboBoxItem when it is in a ListGrid vs when it's in a DynamicForm.
In a DynamicForm if you were to type in a value that does NOT have a match in the valueMap and then leave the field, it would return to the previous value.
In an editable ListGrid if you were to type in a value that does NOT have a match in the valueMap and then leave the field, it would keep what ever characters you typed and try to save the edits with that string.
Walkthrough
The code used in the walkthrough
isc.VLayout.create({
height: 500,
width: 900,
margin: 100,
members: [
isc.ListGrid.create({
height: "100%",
width: "100%",
canEdit: true,
modalEditing: true,
extraSpace: 5,
fields: [
{ name: "Name", canEdit: true, },
{
name: "State",
type: "ComboBoxItem",
canEdit: true,
valueMap: {
WI: "Wisconsin",
IL: "Illinois",
MN: "Minnesota",
MI: "Michigan"
},
addUnknownValues: false,
//allowEmptyValue: false,
completeOnTab: true
}
],
data: [
{ Name: "Evan", State: "WI" },
{ Name: "Erik", State: "IL" },
{ Name: "Philip", State: "MI" },
]
}),
isc.DynamicForm.create({
height: "100%",
width: "100%",
border: "1px solid #ababab",
canEdit: true,
fields: [
{ name: "Name", canEdit: true, },
{
name: "State",
type: "ComboBoxItem",
canEdit: true,
valueMap: {
WI: "Wisconsin",
IL: "Illinois",
MN: "Minnesota",
MI: "Michigan"
},
addUnknownValues: false,
allowEmptyValue: false,
completeOnTab: true
}
],
values: { Name: "Evan", State: "WI" }
})
]
});
It would appear that addUnknownValues has a different effect on the two instances.
I solved the issue by moving addUnknownValues to the ListGridField's editorProperties
this is the updated ListGridField item
{
name: "State",
type: "ComboBoxItem",
canEdit: true,
valueMap: {
WI: "Wisconsin",
IL: "Illinois",
MN: "Minnesota",
MI: "Michigan"
},
editorProperties:{
addUnknownValues: false,
allowEmptyValue: false,
completeOnTab: true
}
}
Hi I recently started working on MVC4 with Razor View Engine, i am using Entity Framework 5 for My Data-access, I need to display user information in UI, so i implemented Flexigrid with the help of Codeproject Article, but this is not working out for me. When i Run my application nothing is displaying except plain old inbuilt index page. I am trying to implement the Flexigrid in Index page only.
My View Code Looks Like
{
<table id="notification" style="display:none">
<script type="text/javascript">
$("#notifications").flexigrid({
url: 'Controllers/Notifications/NotificationsList',
dataType: 'json',
colModel: [
{ display: 'NotificationID', name: 'NotificationID', width: 40, sortable: true, align: 'left' },
{ display: 'Notification', name: 'Notification', width: 100, sortable: true, align: 'left' },
{ display: 'IsDisplay', name: 'IsDisplay', width: 100, sortable: true, align: 'left' },
{ display: 'CreatedBy', name: 'CreatedBy', width: 100, sortable: true, align: 'left' },
{ display: 'CreatedOn', name: 'CreatedOn', width: 100, sortable: true, align: 'left' },
{ display: 'ModifiedBy', name: 'ModifiedBy', width: 80, sortable: true, align: 'left' },
{ display: 'ModifiedOn', name: 'ModifiedOn', width: 60, sortable: true, align: 'left' }
],
searchitems: [
{ display: 'NotificationID', name: 'NotificationID' },
{ display: 'Notification', name: 'Notification' },
{ display: 'IsDisplay', name: 'IsDisplay' },
{ display: 'CreatedBy', name: 'CreatedBy' },
{ display: 'CreatedOn', name: 'CreatedOn' },
{ display: 'ModifiedBy', name: 'ModifiedBy' }
],
sortname: 'NotificationId',
sortorder: 'asc',
usepager: true,
title: 'Notifications',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 1040,
height: 380
});
</script>
</table>
}
Controller Look Like
{
public ActionResult NotificationsList()
{
var q = from c in db.Tbl_Notification
select c;
List<Tbl_Notification> notes = q.ToList();
FlexigridObject flexigridObject = new FlexigridObject();
flexigridObject.page = 1;
flexigridObject.total = db.Tbl_Notification.Count();
foreach (Tbl_Notification notify in notes)
{
FlexigridRow cell = new FlexigridRow()
{
id = notify.NotificationId,
cell = GetPropertyList(notify)
};
flexigridObject.rows.Add(cell);
}
return View("FlexigridObject", flexigridObject);
}
private List<string> GetPropertyList(object obj)
{
List<string> propertyList = new List<string>();
Type type = obj.GetType();
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (PropertyInfo property in properties)
{
object o = property.GetValue(obj, null);
propertyList.Add(o == null ? "" : o.ToString());
}
return propertyList;
}
}
public static class ExtensionMethods
{
public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string propertyName, bool asc)
{
var type = typeof(T);
string methodName = asc ? "OrderBy" : "OrderByDescending";
var property = type.GetProperty(propertyName);
var parameter = Expression.Parameter(type, "p");
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var orderByExp = Expression.Lambda(propertyAccess, parameter);
MethodCallExpression resultExp = Expression.Call(typeof(Queryable), methodName, new Type[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));
return source.Provider.CreateQuery<T>(resultExp);
}
public static IQueryable<T> Like<T>(this IQueryable<T> source, string propertyName, string keyword)
{
var type = typeof(T);
var property = type.GetProperty(propertyName);
var parameter = Expression.Parameter(type, "p");
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var constant = Expression.Constant("%" + keyword + "%");
MethodCallExpression methodExp = Expression.Call(null, typeof(SqlMethods).GetMethod("Like", new Type[] { typeof(string), typeof(string) }), propertyAccess, constant);
Expression<Func<T, bool>> lambda = Expression.Lambda<Func<T, bool>>(methodExp, parameter);
return source.Where(lambda);
}
}
}
I need to implememnt Grid at any cost, please suggest me. and please let me know weather the Kendo UI is free to use?.
It looks like you may have missed adding the $(document).ready() function call around the flexigrid script. Thus, the browser doesn't invoke your flexigrid at all.
Try this:
<table id="notification" style="display:none">
<script type="text/javascript">
$(document).ready(function () {
$("#notifications").flexigrid({
url: 'Controllers/Notifications/NotificationsList',
dataType: 'json',
colModel: [
{ display: 'NotificationID', name: 'NotificationID', width: 40, sortable: true, align: 'left' },
{ display: 'Notification', name: 'Notification', width: 100, sortable: true, align: 'left' },
{ display: 'IsDisplay', name: 'IsDisplay', width: 100, sortable: true, align: 'left' },
{ display: 'CreatedBy', name: 'CreatedBy', width: 100, sortable: true, align: 'left' },
{ display: 'CreatedOn', name: 'CreatedOn', width: 100, sortable: true, align: 'left' },
{ display: 'ModifiedBy', name: 'ModifiedBy', width: 80, sortable: true, align: 'left' },
{ display: 'ModifiedOn', name: 'ModifiedOn', width: 60, sortable: true, align: 'left' }
],
searchitems: [
{ display: 'NotificationID', name: 'NotificationID' },
{ display: 'Notification', name: 'Notification' },
{ display: 'IsDisplay', name: 'IsDisplay' },
{ display: 'CreatedBy', name: 'CreatedBy' },
{ display: 'CreatedOn', name: 'CreatedOn' },
{ display: 'ModifiedBy', name: 'ModifiedBy' }
],
sortname: 'NotificationId',
sortorder: 'asc',
usepager: true,
title: 'Notifications',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 1040,
height: 380
});
});
</script>
</table>
Also, it may not be the best idea to have your script reside inside table layout. Makes for a tag soup.
I have an app that worked great for 2.0p5. I was able to set the various columns in the chart specific colors. In the chart config, I added
colors: [
'#89A54E',
'#4572A7',
'#AA4643'
],
When I upgraded to 2.0rc1, the colors no longer seem to get set. My chart config is:
Ext.create('Rally.ui.chart.Chart', {
animate: true,
chartData: {
series: [{
type: 'column',
name: 'Data1',
data: data1
},
{
type: 'column',
name: 'Data2',
data: data2
},
{
type: 'column',
name: 'Data3',
data: data3
}],
categories: xAxisData
},
chartConfig: {
chart: {
type: 'column'
},
title: {
text: 'Show Data'
},
yAxis: {
min: 0,
title: {
text: 'yAxis Info'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: 'gray'
}
}
},
legend: {
align: 'right',
x: -100,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>'+
'Total: '+ this.point.stackTotal;
}
},
colors: [
'#89A54E',
'#4572A7',
'#AA4643'
],
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: 'white'
}
}
}
}
});
Any ideas why I lost my color setting capabilities in 2.0rc1?
An example from one of my apps:
var series = [{
name : 'Col 1',
data : [],
showInLegend : false
},{
name : 'Col 2',
data : [],
showInLegend : false
},{
name : 'Col 3',
data : [],
showInLegend : false
}];
Ext.Array.each(records, function(record) {
//HighCharts Data
record.set('name', ...);
record.set('y', ...);
record.set('color', ...);
//Add record to series
series[index].data.push(record.data);
// Add to chartData
});
Hope this helps/works for you!