Home > front end >  A column display conversion in datatables
A column display conversion in datatables

Time:09-29

Using datatables plugin in the page displays the contents of the database, the data of normal display on the page, my code:
<script type="text/javascript">
The $(document). Ready (function ()
{
$. Ajax ({
Url: "dispData ashx,"
Type: "post",
Success: the function (tt)
{
//the console. The log (data);
Var data=https://bbs.csdn.net/topics/JSON.parse (tt);//pass the string into a json object
$(' # example1). DataTable ({
The paging: true,
Sort: false,
Searching: false,
Data: data,
The columns: [
{' data ':' id '},
{' data ':' name '},
{' data ':' a datetime '},
{' data ':' data '},
{' data ':' tn},
]
})
}
});
});
</script>
Tn in the database field values respectively 1, 2, 3, I'd like to have 1 to "travel", 2 to "work", 3 to "off" display on the page, could you tell me how to write in the ajax! thank you

CodePudding user response:

Column attributes of the formatter should consult:
$(' # dg). The datagrid ({
The columns: [[
{field: 'userId', the title: 'User', width: 80,
The formatter: function (the value, the row, the index) {
If (row. User) {
Return row. User. The name;
} else {
return value;
}
}
}
]]
});

CodePudding user response:

Thank you upstairs, the problem has been solved, now and then I ask, how to travel, work and rest in a different color
  • Related