Codes Recipes
Codes Recipes

Reputation: 33

How to add an icon in search box in Datatables

need a icon for search box in datatables...

$('#idt-table').DataTable( {
    "oLanguage": { "Search": '<i class="icon-search"></i>' },
    "responsive": true,
    "scrollY": "260px",
    "scrollCollapse": true
});

Upvotes: 2

Views: 16038

Answers (3)

Andre van Rensburg
Andre van Rensburg

Reputation: 161

Here is an example of a spinner in the same type of usage requirement as yours. *Pay attention to the usage of double quotes inside single quotes, or vise versa:

processing: "<i class='fa fa-spinner fa-spin' style='font-size:24px; color: #34495e;'></i>"

Upvotes: 0

user3207354
user3207354

Reputation: 69

Hello you can do this to add search icon into filter of datatable :

#{your-id}_filter .form-control {
    background: url(../images/xxx.svg);    
    background-repeat: no-repeat;
    background-position: 0px 3px !important;
}

Upvotes: 0

annoyingmouse
annoyingmouse

Reputation: 5699

A tiny wee bit of CSS and some playing with SVG should work here (and a quick hint: look up (at the top of this page)):

#idt-table_filter .form-control{
    background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIiAgIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIgICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgICB2ZXJzaW9uPSIxLjEiICAgaWQ9InN2ZzQ0ODUiICAgdmlld0JveD0iMCAwIDIxLjk5OTk5OSAyMS45OTk5OTkiICAgaGVpZ2h0PSIyMiIgICB3aWR0aD0iMjIiPiAgPGRlZnMgICAgIGlkPSJkZWZzNDQ4NyIgLz4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AgY2xhc3M9InN0NCIgICAgICAgICB0cmFuc2Zvcm09Im1hdHJpeCgwLjY5NjQsLTAuNzE3NiwwLjcxNzYsMC42OTY0LC0xNDIuMzkzOCwyMS41MDE1KSIgICAgICAgICB5PSIxNzYuNjAwMDEiICAgICAgICAgeD0iLTQ2LjIwMDAwMSIgLz4gICAgPC9nPiAgPC9nPjwvc3ZnPg==);
    background-repeat: no-repeat;
    background-color: #fff;
    background-position: 0px 3px !important;
}

Working here: https://jsfiddle.net/annoyingmouse/qd4w6a5o/

Basically you're setting the background image of the input to an image which is a base64 encoded SVG (though you could use a different image format). You could easily enough change the image as well with the use of Inkscape. Simply copy the data url into the address of your browser and open it. Download it and edit it to your hearts content, then use http://b64.io/ to convert into a data url again...

Or you could just embed the SVG like this:

background-image: url('data:image/svg+xml;utf8,<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" id="spyglass" viewBox="0 0 22 22" height="22" width="22"><path d="m 10.011718,5.0898489 c -2.7000005,0 -4.9003915,2.2004 -4.9003915,4.9003996 0,2.6999995 2.200391,4.8983995 4.9003915,4.8983995 1.154374,0 2.204251,-0.4184 3.042969,-1.0898 l 3.207031,3.1113 0.626953,-0.6465 -3.185547,-3.0879 c 0.743242,-0.8594 1.208984,-1.964 1.208984,-3.1854995 0,-2.6999996 -2.20039,-4.9003996 -4.90039,-4.9003996 z m 0,1 c 2.2,0 3.90039,1.7004 3.90039,3.9003996 0,2.1999995 -1.70039,3.8983995 -3.90039,3.8983995 -2.2000005,0 -3.9003915,-1.6984 -3.9003915,-3.8983995 0,-2.1999996 1.700391,-3.9003996 3.9003915,-3.9003996 z" style="fill:#808080"/></svg>');

(I didn't know you could embed SVGs now).

Upvotes: 4

Related Questions