function createTable(data, str){
var html ="";
for (i = 0; i < data.length; i++){
var color = ['#bad7ff','#a0f0f7'];
var arr = [];
color.forEach((el,i)=>{
arr[i] = '<tr id="trTOJ">' +
'<td bgcolor="'+color[i]+'">' + data[i].cod + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].nr + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].or + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].np + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].op + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].is + '</td>' +
'<td bgcolor="'+color[i]+'">' + data[i].vr + '</td>';
});
var a = '<td class="btn btn-info btn-ioj" id="infoOrderJournal" data1="'+data[i].nr+'" data2="'+data[i].prim+'"\n\
>' +'Оформление'+ '</td>' +
'</tr>';
var b = '<td class="btn btn-info btn-woj " id="warningOrderJournal" data1="'+data[i].nr+'" \n\
data2="'+data[i].prim+'">' +'Исполнение'+ '</td>' +
'</tr>';
if(str == 3){
if(data[i].st === 0 && data[i].is == 'текст1')html += arr[0]+a;
if(data[i].st === 1 && data[i].is == 'текст1')html += arr[1]+b;
}
else if(str == 4){
if(data[i].st === 0 && data[i].is == 'текст2')html += arr[0]+a;
if(data[i].st === 1 && data[i].is == 'текст2')html += arr[1]+b;
}
else{
if(data[i].st === 0)html += arr[0] + a;
if(data[i].st === 1)html += arr[1] + b;
}
}
$('#table').html(html);
}
если прям по максимум надо, можно и оставшиеся хвосты сжать.