DataTables Filtering on Alt Strings
Using DataTables 1.10.19 and this plugin, I am using the alt
attribute as the data to sort upon.
This works;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
This doesn't work;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com?id=' + row[0] + '&approvalcode=' + row[9] + '"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
Seems t be when I add in the row
URL query strings it breaks the alt
filter, although everything else works as expected.
Plugin code is below;
/**
* Sort on the 'alt' tag of images in a column. This is particularly useful if
* you have a column of images (ticks and crosses for example) and you want to
* control the sorting using the alt tag.
*
* @name Alt string
* @summary Use the `alt` attribute of an image tag as the data to sort upon.
* @author _Jumpy_
*
* @example
* $('#example').dataTable( {
* columnDefs: [
* { type: 'alt-string', targets: 0 }
* ]
* } );
*/
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-string-pre": function ( a ) {
return a.match(/alt="(.*?)"/)[1].toLowerCase();
},
"alt-string-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-string-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
javascript jquery html datatables filtering
add a comment |
Using DataTables 1.10.19 and this plugin, I am using the alt
attribute as the data to sort upon.
This works;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
This doesn't work;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com?id=' + row[0] + '&approvalcode=' + row[9] + '"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
Seems t be when I add in the row
URL query strings it breaks the alt
filter, although everything else works as expected.
Plugin code is below;
/**
* Sort on the 'alt' tag of images in a column. This is particularly useful if
* you have a column of images (ticks and crosses for example) and you want to
* control the sorting using the alt tag.
*
* @name Alt string
* @summary Use the `alt` attribute of an image tag as the data to sort upon.
* @author _Jumpy_
*
* @example
* $('#example').dataTable( {
* columnDefs: [
* { type: 'alt-string', targets: 0 }
* ]
* } );
*/
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-string-pre": function ( a ) {
return a.match(/alt="(.*?)"/)[1].toLowerCase();
},
"alt-string-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-string-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
javascript jquery html datatables filtering
Can you show a better code excerpt from your html and how you initialize the data tables and plugin.
– Honkalonkalooooohhh
Nov 20 '18 at 13:24
Alright, take a look at this FIDDLE and tell me if that'S what you want. Ofc you have to adjust the rows targeted and your data will be something different. But i guess you could just get therow[wherevermylinkisindex]
– Honkalonkalooooohhh
Nov 20 '18 at 14:19
Alright last try for now. If condition is true it'll render the link with query params and alt tag. Sorting by alt will work. Switched to codepen cause fiddle kinda shredded my memory. Example
– Honkalonkalooooohhh
Nov 20 '18 at 15:10
add a comment |
Using DataTables 1.10.19 and this plugin, I am using the alt
attribute as the data to sort upon.
This works;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
This doesn't work;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com?id=' + row[0] + '&approvalcode=' + row[9] + '"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
Seems t be when I add in the row
URL query strings it breaks the alt
filter, although everything else works as expected.
Plugin code is below;
/**
* Sort on the 'alt' tag of images in a column. This is particularly useful if
* you have a column of images (ticks and crosses for example) and you want to
* control the sorting using the alt tag.
*
* @name Alt string
* @summary Use the `alt` attribute of an image tag as the data to sort upon.
* @author _Jumpy_
*
* @example
* $('#example').dataTable( {
* columnDefs: [
* { type: 'alt-string', targets: 0 }
* ]
* } );
*/
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-string-pre": function ( a ) {
return a.match(/alt="(.*?)"/)[1].toLowerCase();
},
"alt-string-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-string-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
javascript jquery html datatables filtering
Using DataTables 1.10.19 and this plugin, I am using the alt
attribute as the data to sort upon.
This works;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
This doesn't work;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com?id=' + row[0] + '&approvalcode=' + row[9] + '"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
Seems t be when I add in the row
URL query strings it breaks the alt
filter, although everything else works as expected.
Plugin code is below;
/**
* Sort on the 'alt' tag of images in a column. This is particularly useful if
* you have a column of images (ticks and crosses for example) and you want to
* control the sorting using the alt tag.
*
* @name Alt string
* @summary Use the `alt` attribute of an image tag as the data to sort upon.
* @author _Jumpy_
*
* @example
* $('#example').dataTable( {
* columnDefs: [
* { type: 'alt-string', targets: 0 }
* ]
* } );
*/
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-string-pre": function ( a ) {
return a.match(/alt="(.*?)"/)[1].toLowerCase();
},
"alt-string-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-string-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
javascript jquery html datatables filtering
javascript jquery html datatables filtering
edited Nov 20 '18 at 14:05
asked Nov 20 '18 at 12:47
TheOrdinaryGeek
818215
818215
Can you show a better code excerpt from your html and how you initialize the data tables and plugin.
– Honkalonkalooooohhh
Nov 20 '18 at 13:24
Alright, take a look at this FIDDLE and tell me if that'S what you want. Ofc you have to adjust the rows targeted and your data will be something different. But i guess you could just get therow[wherevermylinkisindex]
– Honkalonkalooooohhh
Nov 20 '18 at 14:19
Alright last try for now. If condition is true it'll render the link with query params and alt tag. Sorting by alt will work. Switched to codepen cause fiddle kinda shredded my memory. Example
– Honkalonkalooooohhh
Nov 20 '18 at 15:10
add a comment |
Can you show a better code excerpt from your html and how you initialize the data tables and plugin.
– Honkalonkalooooohhh
Nov 20 '18 at 13:24
Alright, take a look at this FIDDLE and tell me if that'S what you want. Ofc you have to adjust the rows targeted and your data will be something different. But i guess you could just get therow[wherevermylinkisindex]
– Honkalonkalooooohhh
Nov 20 '18 at 14:19
Alright last try for now. If condition is true it'll render the link with query params and alt tag. Sorting by alt will work. Switched to codepen cause fiddle kinda shredded my memory. Example
– Honkalonkalooooohhh
Nov 20 '18 at 15:10
Can you show a better code excerpt from your html and how you initialize the data tables and plugin.
– Honkalonkalooooohhh
Nov 20 '18 at 13:24
Can you show a better code excerpt from your html and how you initialize the data tables and plugin.
– Honkalonkalooooohhh
Nov 20 '18 at 13:24
Alright, take a look at this FIDDLE and tell me if that'S what you want. Ofc you have to adjust the rows targeted and your data will be something different. But i guess you could just get the
row[wherevermylinkisindex]
– Honkalonkalooooohhh
Nov 20 '18 at 14:19
Alright, take a look at this FIDDLE and tell me if that'S what you want. Ofc you have to adjust the rows targeted and your data will be something different. But i guess you could just get the
row[wherevermylinkisindex]
– Honkalonkalooooohhh
Nov 20 '18 at 14:19
Alright last try for now. If condition is true it'll render the link with query params and alt tag. Sorting by alt will work. Switched to codepen cause fiddle kinda shredded my memory. Example
– Honkalonkalooooohhh
Nov 20 '18 at 15:10
Alright last try for now. If condition is true it'll render the link with query params and alt tag. Sorting by alt will work. Switched to codepen cause fiddle kinda shredded my memory. Example
– Honkalonkalooooohhh
Nov 20 '18 at 15:10
add a comment |
1 Answer
1
active
oldest
votes
Inital value of first column will be 0
or 1
. If the value is 1
a link with query parameters is inserted and the <i>
will get the alt="Processed"
. Otherwise the link will be inserted without parameters and the alt value will be "Not Processed"
. Rendered table will then be ordered by the alt attributes of the <i>
inside the first column. I also just concatenate the html string with +
. I parse the data value to int since it is handed as a string. If i don't do this it will never append the query parameters.
$(document).ready(function() {
$("#example").DataTable({
columnDefs: [
{
type: "alt-string",
targets: 0,
render: function(data, type, row, meta) {
if (parseInt(data) === 1) {
return (
'<a href="www.example.com?id=' +
row[2] +
"&approvalcode=" +
row[3] +
'"><i class="icon-ok" alt="Processed">link' +
row[2] +
"</i></a>"
);
} else {
return (
'<a href="www.example.com"><i class="icon-ok" alt="New">link' +
row[2] +
"</i></a>"
);
}
}
}
]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/alt-string.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1007</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>2</td>
<td>7001</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>3</td>
<td>42</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>4</td>
<td>1337</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>5</td>
<td>80085</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</tfoot>
</table>
1
So in your example, searching for 'processed' should display those results where the condition =1
? Because this doesn't work.
– TheOrdinaryGeek
Nov 20 '18 at 16:55
The above example is just showing the sorting by alt tags of dynamically rendered content, not the filtering/search. You can search for the links names but not the alt tags.
– Honkalonkalooooohhh
Nov 21 '18 at 10:41
If you need to make the search work, maybe take a look into Custom filtering.
– Honkalonkalooooohhh
Nov 21 '18 at 11:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393329%2fdatatables-filtering-on-alt-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Inital value of first column will be 0
or 1
. If the value is 1
a link with query parameters is inserted and the <i>
will get the alt="Processed"
. Otherwise the link will be inserted without parameters and the alt value will be "Not Processed"
. Rendered table will then be ordered by the alt attributes of the <i>
inside the first column. I also just concatenate the html string with +
. I parse the data value to int since it is handed as a string. If i don't do this it will never append the query parameters.
$(document).ready(function() {
$("#example").DataTable({
columnDefs: [
{
type: "alt-string",
targets: 0,
render: function(data, type, row, meta) {
if (parseInt(data) === 1) {
return (
'<a href="www.example.com?id=' +
row[2] +
"&approvalcode=" +
row[3] +
'"><i class="icon-ok" alt="Processed">link' +
row[2] +
"</i></a>"
);
} else {
return (
'<a href="www.example.com"><i class="icon-ok" alt="New">link' +
row[2] +
"</i></a>"
);
}
}
}
]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/alt-string.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1007</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>2</td>
<td>7001</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>3</td>
<td>42</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>4</td>
<td>1337</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>5</td>
<td>80085</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</tfoot>
</table>
1
So in your example, searching for 'processed' should display those results where the condition =1
? Because this doesn't work.
– TheOrdinaryGeek
Nov 20 '18 at 16:55
The above example is just showing the sorting by alt tags of dynamically rendered content, not the filtering/search. You can search for the links names but not the alt tags.
– Honkalonkalooooohhh
Nov 21 '18 at 10:41
If you need to make the search work, maybe take a look into Custom filtering.
– Honkalonkalooooohhh
Nov 21 '18 at 11:19
add a comment |
Inital value of first column will be 0
or 1
. If the value is 1
a link with query parameters is inserted and the <i>
will get the alt="Processed"
. Otherwise the link will be inserted without parameters and the alt value will be "Not Processed"
. Rendered table will then be ordered by the alt attributes of the <i>
inside the first column. I also just concatenate the html string with +
. I parse the data value to int since it is handed as a string. If i don't do this it will never append the query parameters.
$(document).ready(function() {
$("#example").DataTable({
columnDefs: [
{
type: "alt-string",
targets: 0,
render: function(data, type, row, meta) {
if (parseInt(data) === 1) {
return (
'<a href="www.example.com?id=' +
row[2] +
"&approvalcode=" +
row[3] +
'"><i class="icon-ok" alt="Processed">link' +
row[2] +
"</i></a>"
);
} else {
return (
'<a href="www.example.com"><i class="icon-ok" alt="New">link' +
row[2] +
"</i></a>"
);
}
}
}
]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/alt-string.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1007</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>2</td>
<td>7001</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>3</td>
<td>42</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>4</td>
<td>1337</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>5</td>
<td>80085</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</tfoot>
</table>
1
So in your example, searching for 'processed' should display those results where the condition =1
? Because this doesn't work.
– TheOrdinaryGeek
Nov 20 '18 at 16:55
The above example is just showing the sorting by alt tags of dynamically rendered content, not the filtering/search. You can search for the links names but not the alt tags.
– Honkalonkalooooohhh
Nov 21 '18 at 10:41
If you need to make the search work, maybe take a look into Custom filtering.
– Honkalonkalooooohhh
Nov 21 '18 at 11:19
add a comment |
Inital value of first column will be 0
or 1
. If the value is 1
a link with query parameters is inserted and the <i>
will get the alt="Processed"
. Otherwise the link will be inserted without parameters and the alt value will be "Not Processed"
. Rendered table will then be ordered by the alt attributes of the <i>
inside the first column. I also just concatenate the html string with +
. I parse the data value to int since it is handed as a string. If i don't do this it will never append the query parameters.
$(document).ready(function() {
$("#example").DataTable({
columnDefs: [
{
type: "alt-string",
targets: 0,
render: function(data, type, row, meta) {
if (parseInt(data) === 1) {
return (
'<a href="www.example.com?id=' +
row[2] +
"&approvalcode=" +
row[3] +
'"><i class="icon-ok" alt="Processed">link' +
row[2] +
"</i></a>"
);
} else {
return (
'<a href="www.example.com"><i class="icon-ok" alt="New">link' +
row[2] +
"</i></a>"
);
}
}
}
]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/alt-string.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1007</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>2</td>
<td>7001</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>3</td>
<td>42</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>4</td>
<td>1337</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>5</td>
<td>80085</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</tfoot>
</table>
Inital value of first column will be 0
or 1
. If the value is 1
a link with query parameters is inserted and the <i>
will get the alt="Processed"
. Otherwise the link will be inserted without parameters and the alt value will be "Not Processed"
. Rendered table will then be ordered by the alt attributes of the <i>
inside the first column. I also just concatenate the html string with +
. I parse the data value to int since it is handed as a string. If i don't do this it will never append the query parameters.
$(document).ready(function() {
$("#example").DataTable({
columnDefs: [
{
type: "alt-string",
targets: 0,
render: function(data, type, row, meta) {
if (parseInt(data) === 1) {
return (
'<a href="www.example.com?id=' +
row[2] +
"&approvalcode=" +
row[3] +
'"><i class="icon-ok" alt="Processed">link' +
row[2] +
"</i></a>"
);
} else {
return (
'<a href="www.example.com"><i class="icon-ok" alt="New">link' +
row[2] +
"</i></a>"
);
}
}
}
]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/alt-string.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1007</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>2</td>
<td>7001</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>3</td>
<td>42</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>4</td>
<td>1337</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>5</td>
<td>80085</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</tfoot>
</table>
$(document).ready(function() {
$("#example").DataTable({
columnDefs: [
{
type: "alt-string",
targets: 0,
render: function(data, type, row, meta) {
if (parseInt(data) === 1) {
return (
'<a href="www.example.com?id=' +
row[2] +
"&approvalcode=" +
row[3] +
'"><i class="icon-ok" alt="Processed">link' +
row[2] +
"</i></a>"
);
} else {
return (
'<a href="www.example.com"><i class="icon-ok" alt="New">link' +
row[2] +
"</i></a>"
);
}
}
}
]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/alt-string.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1007</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>2</td>
<td>7001</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>3</td>
<td>42</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>4</td>
<td>1337</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>5</td>
<td>80085</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</tfoot>
</table>
$(document).ready(function() {
$("#example").DataTable({
columnDefs: [
{
type: "alt-string",
targets: 0,
render: function(data, type, row, meta) {
if (parseInt(data) === 1) {
return (
'<a href="www.example.com?id=' +
row[2] +
"&approvalcode=" +
row[3] +
'"><i class="icon-ok" alt="Processed">link' +
row[2] +
"</i></a>"
);
} else {
return (
'<a href="www.example.com"><i class="icon-ok" alt="New">link' +
row[2] +
"</i></a>"
);
}
}
}
]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/alt-string.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1007</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>2</td>
<td>7001</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>3</td>
<td>42</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>4</td>
<td>1337</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>5</td>
<td>80085</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Link</th>
<th>Condition</th>
<th>ID</th>
<th>Code</th>
</tr>
</tfoot>
</table>
edited Nov 21 '18 at 9:51
answered Nov 20 '18 at 15:41
Honkalonkalooooohhh
1016
1016
1
So in your example, searching for 'processed' should display those results where the condition =1
? Because this doesn't work.
– TheOrdinaryGeek
Nov 20 '18 at 16:55
The above example is just showing the sorting by alt tags of dynamically rendered content, not the filtering/search. You can search for the links names but not the alt tags.
– Honkalonkalooooohhh
Nov 21 '18 at 10:41
If you need to make the search work, maybe take a look into Custom filtering.
– Honkalonkalooooohhh
Nov 21 '18 at 11:19
add a comment |
1
So in your example, searching for 'processed' should display those results where the condition =1
? Because this doesn't work.
– TheOrdinaryGeek
Nov 20 '18 at 16:55
The above example is just showing the sorting by alt tags of dynamically rendered content, not the filtering/search. You can search for the links names but not the alt tags.
– Honkalonkalooooohhh
Nov 21 '18 at 10:41
If you need to make the search work, maybe take a look into Custom filtering.
– Honkalonkalooooohhh
Nov 21 '18 at 11:19
1
1
So in your example, searching for 'processed' should display those results where the condition =
1
? Because this doesn't work.– TheOrdinaryGeek
Nov 20 '18 at 16:55
So in your example, searching for 'processed' should display those results where the condition =
1
? Because this doesn't work.– TheOrdinaryGeek
Nov 20 '18 at 16:55
The above example is just showing the sorting by alt tags of dynamically rendered content, not the filtering/search. You can search for the links names but not the alt tags.
– Honkalonkalooooohhh
Nov 21 '18 at 10:41
The above example is just showing the sorting by alt tags of dynamically rendered content, not the filtering/search. You can search for the links names but not the alt tags.
– Honkalonkalooooohhh
Nov 21 '18 at 10:41
If you need to make the search work, maybe take a look into Custom filtering.
– Honkalonkalooooohhh
Nov 21 '18 at 11:19
If you need to make the search work, maybe take a look into Custom filtering.
– Honkalonkalooooohhh
Nov 21 '18 at 11:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393329%2fdatatables-filtering-on-alt-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you show a better code excerpt from your html and how you initialize the data tables and plugin.
– Honkalonkalooooohhh
Nov 20 '18 at 13:24
Alright, take a look at this FIDDLE and tell me if that'S what you want. Ofc you have to adjust the rows targeted and your data will be something different. But i guess you could just get the
row[wherevermylinkisindex]
– Honkalonkalooooohhh
Nov 20 '18 at 14:19
Alright last try for now. If condition is true it'll render the link with query params and alt tag. Sorting by alt will work. Switched to codepen cause fiddle kinda shredded my memory. Example
– Honkalonkalooooohhh
Nov 20 '18 at 15:10