add more options in records per page dropdown using datatable jquery - datatables

I've been using the datatable jquery (http://datatables.net/ ) plugin.
Everything is working fine, but now I want to be able to select more than the default options of records per page, by default I can choose 10 , 25 , 50 , 100. I want to add 15 and 30 to this list.
How can I do that, I searched on internet but could't find any answer.
Thanks

Use pageLength and lengthMenu for setting the default view, like this:
$('#example').DataTable({
"pageLength": 15,
"lengthMenu": [[10, 15, 25, 35, 50, 100, -1], [10, 15, 25, 35, 50, 100, "All"]]
});
old api
$('#example').dataTable({
"iDisplayLength": 15,
"aLengthMenu": [[10, 15, 25, 35, 50, 100, -1], [10, 15, 25, 35, 50, 100, "All"]]
});
Second array will hold the values for that will be displayed in the drop down menu
Read more: DataTables example - Page length options

Related

np.array for variable matrix

import numpy as np
data = np.array([[10, 20, 30, 40, 50, 60, 70, 80, 90],
[2, 7, 8, 9, 10, 11],
[3, 12, 13, 14, 15, 16],
[4, 3, 4, 5, 6, 7, 10, 12]],dtype=object)
target = data[:,0]
It has this error.
IndexError Traceback (most recent call last)
Input In \[82\], in \<cell line: 9\>()
data = np.array(\[\[10, 20, 30, 40, 50, 60, 70, 80, 90\],
\[2, 7, 8, 9, 10, 11\],
\[3, 12, 13, 14, 15, 16\],
\[4, 3, 4, 5, 6, 7, 10,12\]\],dtype=object)
# Define the target data ----\> 9 target = data\[:,0\]
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
May I know how to fix it, please? I mean do not change the elements in the data. Many thanks. I made the matrix in the same size and the error message was gone. But I have the data with variable size.
You have a array of objects, so you can't use indexing on axis=1 as there is none (data.shape -> (4,)).
Use a list comprehension:
out = np.array([a[0] for a in data])
Output: array([10, 2, 3, 4])

How to increase 1d-data resolution though interpolating in between measurements?

I'm developing a pythong script where I receive angular measurements from a motor which has a low resolution encoder attached to it. The data I get from the motor has a very low resolution (about 5 degrees division in between measurments). This is an example of the sensor output whilst it is rotating with a constant speed (in degrees):
sensor output = ([5, 5, 5, 5, 5, 10, 10, 10, 10 ,10, 15, 15, 20, 20, 20, 20, 25, 25, 30, 30, 30, 30, 30, 35, 35....])
As you can see, some of these measurements are repeating themselves.
From these measurements, I would like to interpolate in order to get the measurements in between the 1D data-points. For instance, if I at time k receive the angular measurement theta=5 and in the next instance at t=k+1 also receive a measurement of theta=5, I would like to compute an estimate that would be something like theta = 5+(1/5).
I have also been considering using some sort of predictive filtering, but I'm not sure which one to apply if that is even applicable in this case (e.g. Kalman filtering). The estimated output should be in a linear form since the motor is rotating with a constast angular velocity.
I have tried using numpy.linspace in order to acheive what I want, but cannot seem to get it to work the way I want:
# Interpolate for every 'theta_div' values in angle received through
# modbus
for k in range(np.size(rx)):
y = T.readSensorData() # take measurement (call read sensor function)
fp = np.linspace(y, y+1, num=theta_div)
for n in range(theta_div):
if k % 6 == 0:
if not y == fp[n]:
z = fp[n]
else:
z = y
print(z)
So for the sensor readings: ([5, 5, 5, 5, 5, 10, 10, 10, 10 ,10, 15, 15, 20, 20, 20, 20, 25, 25, 30, 30, 30, 30, 30, 35, 35....]) # each element at time=k0...kn
I would like the output to be something similar to:
theta = ([5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17.5, 20...])
So in short, I need some sort of prediction and then update the value with the actual reading from the sensor, similar to the procedure in a Kalman filter.
why dont just make a linear fit?
import numpy as np
import matplotlib.pyplot as plt
messurements = np.array([5, 5, 5, 5, 5, 10, 10, 10, 10 ,10, 15, 15, 20, 20, 20, 20, 25, 25, 30, 30, 30, 30, 30, 35, 35])
time_array = np.arange(messurements.shape[0])
fitparms = np.polyfit(time_array,messurements,1)
def line(x,a,b):
return a*x +b
better_time_array = np.linspace(0,np.max(time_array))
plt.plot(time_array,messurements)
plt.plot(better_time_array,line(better_time_array,fitparms[0],fitparms[1]))

How to set auto hight of page for POS software by MPDF in Yii

I am facing a problem when printing pos invoice by MPDF. I don't want to set a fixed height of pdf page. Page height will be adjusted by its content. Here the line of my controller's function from where I am calling MPDF.
$mPDF1 = Yii::app()->ePdf->mpdf('',array('80','130'), 8, '', 5, 5, 5, 5, 0, 0, 'P');
Please give me some idea how to get expected page size.
pls try this
$mpdf=new mPDF('c', 'A4', 0, 'Arial', 10, 10, 10, 10, 10, 10);
OR
$mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');

Length menu being discarded due to sDom in Jquery Datatable?

I have this:
oTable = $("#bla").dataTable({
"iDisplayLength": 50,
"aLengthMenu": [[5, 25, 50, 100, 250, -1], [5, 25, 50, 100, 250, "All"]],
"sDom": "<'call-header'<'dthead'><'ttools'T><'filterinput'f>r><'dttoolbar'><'dataTables_scroll'<'dataTables_scrollBody't>><'call-footer'<'row-fluid'<'span6'i><'span6'p>>>",
.... });
If I comment out the sDom part, I get my length menu and I am able to select the number of items to show on the page. But with the SDOM variable, this just disappears.
I've tried combinations of adding:
<'dataTables_length'>
But I think I am misunderstanding how it works. Can anyone clarify how this must be done?
See the documentation for sDom - the sDom code for Length changing is l.
Here the length menu is being inserted as the very first control :
sDom: "<'call-header'<'dthead'>l<'ttools'T><'filterinput'f>r><'dttoolbar'><'dataTables_scroll'<'dataTables_scrollBody't>><'call-footer'<'row-fluid'<'span6'i><'span6'p>>>"
---^---
fiddle -> http://jsfiddle.net/eCrhb/

kineticjs line points array contentes

what are the interpretation values in the"" points assignment. all I want is a "plane jane" line where I can manipulate the length and width. Any help will greatly appreciated.
var line = new Kinetic.Line({
x: 100,
y: 50,
points: [73, 70, 340, 23, 450, 60, 500, 20],
stroke: 'red',
tension: 1
});
The points array is a series of x,y coordinates:
// [73, 70, 340, 23, 450, 60, 500, 20],
{x:73,y:70},
{x:340,y:23},
{x:450,y:60},
{x:500,y:20}
This is your "plain jane" line:
// draw a black line from 25,25 to 100,50 and width of 5
var line = new Kinetic.Line({
points:[25,25, 100,50],
y:100,
stroke: 'black',
strokeWidth: 5
});