Integration: Ion.RangeSlider + DataTables.net
See original GitHub issueI am trying an integration between DataTables and Ion.RangeSlider, but it is not working. My data is not being filtered when I am using the slider, it works only when I use the inputs.
Here is where I am using: http://myoption.com.br/
Just click on the gear on top right. There you can see the range slider. It should work on the column [6]
called Strike.
Looking to the HTML and JS, do you guys know what am I missing?
<tr>
<td><input type="text" size="5" class="js-input-from" id="min" name="min" value="0" /></td>
<td class="col-8"><input type="text" class="js-range-slider" value="" /></td>
<td><input type="text" size="5" class="js-input-to" id="max" name="max" value="0" /></td>
</tr>
$(function () {
"use strict";
/* Data Table Range Filtering */
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var min = parseInt($('#min').val(), 10);
var max = parseInt($('#max').val(), 10);
var strike = parseFloat(data[6]) || 0; // use data to column number
if ((isNaN(min) && isNaN(max)) ||
(isNaN(min) && strike <= max) ||
(min <= strike && isNaN(max)) ||
(min <= strike && strike <= max)) {
return true;
}
return false;
}
);
// Ion Range Slider
var $range = $(".js-range-slider"),
$inputFrom = $(".js-input-from"),
$inputTo = $(".js-input-to"),
instance,
min = 0,
max = 100,
from = 0,
to = 0;
$range.ionRangeSlider({
type: "double", min: min, max: max,
onStart: updateInputs,
onChange: updateInputs,
onFinish: updateInputs
});
instance = $range.data("ionRangeSlider");
function updateInputs(data) {
from = data.from;
to = data.to;
$inputFrom.prop("value", from);
$inputTo.prop("value", to);
}
$inputFrom.on("input", function () {
var val = $(this).prop("value");
// validate
if (val < min) {
val = min;
} else if (val > to) {
val = to;
}
instance.update({
from: val
});
});
$inputTo.on("input", function () {
var val = $(this).prop("value");
// validate
if (val < from) {
val = from;
} else if (val > max) {
val = max;
}
instance.update({
to: val
});
});
});
$(document).ready(function () {
var table = $('#ajaxTable').DataTable({
ajax: "../../dados/opcoes.json",
columns: [
{ data: 0 },
{ data: 1 },
{ data: 2 },
{ data: 3 },
{ data: 4 },
{ data: 5 },
{ data: 6 },
{ data: 7 },
{ data: 8 },
{ data: 9 },
{ data: 10 },
{ data: 11 },
{ data: 12 },
{ data: 13 },
{ data: 14 },
{ data: 15 },
],
});
// Event listener to the two range filtering inputs to redraw on input
$('#min, #max').keyup(function () {
table.draw();
});
});
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Almost Functional Range Slider — DataTables forums
Hey guys, I am trying to integrate Ion.RangeSlider and DataTable Range Filtering. And look what I've done! It almost work! lol
Read more >Integration: Ion.RangeSlider + DataTables.net - Bountysource
I am trying an integration between DataTables and Ion.RangeSlider, but it is not working. My data is not being filtered when I am...
Read more >Create a range slider for a date - Stack Overflow
I'm using ion range slider but am not tied to it as an option. ... type="text/css" /> <script src="https://nightly.datatables.net/js/jquery.
Read more >DataTables | Material UI 2 - GitHub Pages
This plugin requires material-plugins.css and DataTables official CSS. ... Import DataTables.net CSS (Bootstrap 4 version) before Material CSS.
Read more >Ion.RangeSlider - jQuery Range Slider | IonDen.com
Cross-browser support. Chrome, Firefox, Opera, IE8+; Skin support. 6 beautiful skins included; Support of negative and fractional values; Customisable grid ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Basic idea behind many sliders is that you need to have many of everything else (instances, support functions, etc.)
To not to do it manually (that usually leads to mistakes like yours). I would recommend you to create a wrapper class, which will generate all logic for every range slider you are using and have a public methods to control it.
I can give you a small hint how to do that, but for the rest - please go to StackOverflow. Because this is already an off-topic and your job to figure it out 😃
Hint:
Fixed
http://live.datatables.net/sivelagi/1/edit