Jquery : Add Filter in first row of DataTable two row header.

Friends, whenever we use Jquery DataTable with custom filter option,but major problem occur when we have multiple row header so we need to put filter input on first row of thead so here the solution.

<table id=”tbl_Id” width=”100%”>
<thead>
<tr class=”filter”>
<th></th>
<th>Size</th>
<th>Price</th>
</tr>
<tr >
th>Product Name</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>T-shirt</td>
<td>M </td>
<td>499</td>
</tr>
<tr>
<td>T-shirt 2</td>
<td>M </td>
<td>499</td>
</tr>
</tbody>
</table>

$(“#tbl_Id”).DataTable({
destroy: true,

“paging”: true, initComplete: function () {
var api = this.api();
api.columns().indexes().flatten().each(function (i) {
try {
if (i == 1) {
var column = api.column(i);
$($(“#tbl_Id .filter th:eq(” + i + “)”).empty()).find(“select”).remove();
var select = $(‘All’)
.appendTo($(“#tbl_Id .filter th:eq(” + i + “)”).empty())
.on(‘change’, function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? ‘^’ + val + ‘$’ : ”, true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
if (d != “”)
select.append(” + d + ”)
});
}
} catch (e) { }
});
}
});

Retrieve comma separated column name with list of table name in SQL Server

Select distinct TABLE_NAME,
substring(
(
Select ‘,’+ST1.column_Name AS [text()]
From INFORMATION_SCHEMA.COLUMNS ST1
Where TABLE_NAME =ST2.TABLE_NAME
For XML PATH (”)
), 2, 1000) Columns
From INFORMATION_SCHEMA.COLUMNS ST2

 

Results

TABLE_NAME Columns
ExampleTable PriKey,timestamp,Name
region id,State,ZipCode,City,County
Sheet1$ State,Zip Code,City,Country
TestPri ID,Uname
TestT Name,TID,ID

Get next closest Date according give day name in sql server

Whenever you need closest next date according specify day name then here is sql server query :

DECLARE @NextDayID INT = 0
Declare @day varchar(10)=’Thursday’
if(@Day=’Monday’)
begin
set @NextDayID=0
END
else if(@Day=’Tuesday’)
begin
set @NextDayID=1
END
else if(@Day=’Wednesday’)
begin
set @NextDayID=2
END
else if(@Day=’Thursday’)
begin
set @NextDayID=3
END
else if(@Day=’Friday’)
begin
set @NextDayID=4
END
else if(@Day=’Saturday’)
begin
set @NextDayID=5
END
else if(@Day=’Sunday’)
begin
set @NextDayID=6
END

declare @DateD datetime
SELECT @DateD=( DATEADD(DAY, (DATEDIFF(DAY, @NextDayID, GETDATE()) / 7) * 7 + 7, @NextDayID))

select @DateD

JavaScript String split() Method

Split() method use for split any string into array object using selective character or string.

var str=”Jaipur,Udaipur,Kota,Banswara”;

str is string object;

var ArrObj = str.split(“,”);

ArrObj Return :
[“Jaipur”, “Udaipur”, “Kota”, “Banswara”]

Syntax :

string.split(separator,limit)

Separator : pass character or string value from which you want split string into array object.

Limit : An limit of how much array object will return. if we pass 2 in limit then  only maximum two item will be return([“Jaipur”, “Udaipur”]).

 

 

 

Conditional Operator (?:) in C#

Let’s go with how to conditional operator (?:)  perform in c#. why we use conditional operator in C# ?

For Ex. : We have three variable a,b,c. Now we need to find out maximum number.

Code using If condition :

void  main(arg[])
{

int a=10,b=3;c=45;

int max=0;

if(a>b && b >c)

{

max=a;

}

else if(b>a && b>c)

{

max =b;

}

else

{

max =c;

}

console.WriteLine(“Max => “+max);

}

Now Using Conditional operator :

void  main(arg[])

{

int a=10,b=3;c=45;

int max=0;

max = a>b&&a>c?a:b>a&&b>c?b:c;

console.WriteLine(“Max => “+max);

}

You can see difference in line of code. Basically conditional operator use for simplify multiple if condition in single statement;

condition ? True_expression : False_expression;

 

? return true expression and : use for return false expression.

For Ex.

Condition 1:
int a =1, b= 0,c=0;

c= a==b?1:2;

value of C = 2;

Condition 2:

int a =1, b= 1,c=0;

c= a==b?1:2;

value of C = 1;