-
-
Save yahyaahrika/92a05c33fe6e3448a0980f8db9a7d2df to your computer and use it in GitHub Desktop.
datatables ajax reload new parameters post , change row or edit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public JsonResult Get(DateTime datestart, DateTime datefin) | |
{ | |
SqlCommand SQL = new SqlCommand(); | |
DataTable table = new DataTable(); | |
Object DataFilter = null; | |
try | |
{ | |
SQL.Connection = new SqlConnection(db.Database.Connection.ConnectionString); | |
SQL.CommandType = CommandType.StoredProcedure; | |
SQL.CommandText = "SP_Statistique_Date"; | |
SQL.Parameters.AddWithValue("@dateStart", datestart); | |
SQL.Parameters.AddWithValue("@dateFin", datefin); | |
SQL.Connection.Open(); | |
table.Load(SQL.ExecuteReader()); | |
DataFilter = (from t in table.AsEnumerable().ToList() | |
select new | |
{ | |
idwebsite = t.ItemArray[0], | |
websiteName = t.ItemArray[1].ToString(), | |
offen = t.ItemArray[2], | |
Auftrage = t.ItemArray[3], | |
umsatz = t.ItemArray[4], | |
Anteil = t.ItemArray[5], | |
Drush = t.ItemArray[6], | |
googleads = t.ItemArray[7], | |
KostenpAuftrag = t.ItemArray[8], | |
gewinn = t.ItemArray[9] | |
}).ToList(); | |
return Json(new Dictionary<string, object> | |
{{ "data",DataFilter }},JsonRequestBehavior.AllowGet); | |
} | |
catch (Exception ex) | |
{ | |
return Json(new Dictionary<string, object> | |
{{ "data","" }}, JsonRequestBehavior.AllowGet); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table= $('#allStatique').DataTable({ | |
"processing": true, | |
//"serverSide": true, | |
"ajax": { | |
"url": window.document.location.origin + '/Statistique/Get', | |
"type": 'POST', | |
"data": { | |
"datestart": datastart, | |
"datefin": datafin | |
} | |
}, | |
"columns": [ | |
{ "data": "idwebsite" }, | |
{ "data": "websiteName" }, | |
{ "data": "offen" }, | |
{ "data": "Auftrage" }, | |
{ "data": "umsatz" }, | |
{ "data": "Anteil" }, | |
{ "data": "Drush" }, | |
{ "data": "googleads" }, | |
{ "data": "KostenpAuftrag" }, | |
{ "data": "gewinn" } | |
], | |
rowCallback: function (row, data, index) { | |
gewinn = data.gewinn; | |
if (gewinn >900) { | |
$(row).find('td:eq(9)').css('color', 'green'); | |
} | |
if (gewinn < 900 && gewinn > 0) { | |
$(row).find('td:eq(9)').css('color', 'orange'); | |
} | |
if (gewinn < 0) { | |
$(row).find('td:eq(9)').css('color', 'red'); | |
} | |
} | |
//"columnDefs": [ | |
// { | |
// "targets": 0 | |
// }] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment