After getting data table rows through sAjaxSource i am unable to hide column using aoColumnDefs

After getting data table rows through sAjaxSource i am unable to hide column using aoColumnDefs

suryasurya Posts: 8Questions: 0Answers: 0
edited December 2012 in General
[code]
Id Subcategoryname
NotCombiningAllowed Options
foreach (var item in Model)
{
SubcategoryId @item.Subcategoryname NotCombiningAllowed
  
}
[/code]
[code]


var oTable;
$(document).ready(function () {

oTable = $('#tblSubcategories').dataTable();
var nEditing = null;

$('#tblSubcategories a.edit').live('click', function (e) {
e.preventDefault();

/* Get the row as a parent of the link that was clicked on */
var nRow = $(this).parents('tr')[0];

if (nEditing !== null && nEditing != nRow) {
/* A different row is being edited - the edit should be cancelled and this row edited */
restoreRow(oTable, nEditing);
editRow(oTable, nRow);
nEditing = nRow;

}
else if (nEditing == nRow && this.innerHTML == "Save") {
/* This row is being edited and should be saved */
saveRow(oTable, nEditing);
nEditing = null;
}
else {
/* No row currently being edited */
editRow(oTable, nRow);
nEditing = nRow;
}
});


$('#tblSubcategories a.delete').live('click', function (e) {
e.preventDefault();

var nRow = $(this).parents('tr')[0];
deleteRow(oTable, nRow);

});

$('#new').click(function (e) {
e.preventDefault();

var aiNew = oTable.fnAddData(['0', '','', 'Edit']);
var nRow = oTable.fnGetNodes(aiNew[0]);
editRow(oTable, nRow);
nEditing = nRow;
});
});
function deleteRow(oTable,nRow){
var aData = oTable.fnGetData(nRow);
if ( confirm( "Are you sure you want to delete "+aData[1]+"?" ) )
{
$.ajax({
url: 'DeletesubcategoryRow',
type: 'GET',
cache: false,
data: { Input: aData[0]
},
success: function (data) {
if (data == "True")
oTable.fnDeleteRow(nRow);
else
alert("Error occurs while deleting on DB");
},
error: function (xmlhtt) {
alert("error occurs in ajax call");
//do error handling
}
});
}

}

function editRow(oTable, nRow) {
var aData = oTable.fnGetData(nRow);
var jqTds = $('>td', nRow);
var categoryvalue = $('#categoryId').val();


//getting dropdown
$.ajax({
url: 'Getnotcombiningcategories',
type: 'GET',
cache: false,
data: { Input: aData[0], category: categoryvalue, selectedvalues: aData[5]
},
success: function (data) {
var obj = $.parseJSON(data);

$.each(obj, function () {
$("#dropdown option[value='" + this['Value'] + "']").remove();
$('#dropdown').append('' + this['Text'] + '');
});

},
error: function (xmlhtt) {
alert("error in getting Id count");
//do error handling
}
});

//End of getting dropdown


var strempty = '';


jqTds[0].innerHTML = '';
jqTds[1].innerHTML = '';
jqTds[2].innerHTML = 'Save  ';

}

function saveRow(oTable, nRow) {
var aData = oTable.fnGetData(nRow);
var jqInputs = $('input', nRow);
var selectedinput = $('select', nRow);

var selecteddisplay = [];
selectedinput.each(function (i, selected) {
selecteddisplay[i] = $(selected).val();
});

var categoryvalue = $('#categoryId').val();

//saving to DB
$.ajax({
url: 'EditSubcategory',
type: 'POST',
cache: false,
data: { Inputstring: aData[0] + '^' + jqInputs[0].value + '^' + selecteddisplay + '^' + categoryvalue
},
success: function (data) {

oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
oTable.fnUpdate("" + selecteddisplay + "", nRow, 4, false);
oTable.fnUpdate('   ', nRow, 5, false);



},
error: function (xmlhtt) {
alert("error in saving");
//do error handling
}
});

reloadtable(categoryvalue);

}

function restoreRow(oTable, nRow) {
var aData = oTable.fnGetData(nRow);
var jqTds = $('>td', nRow);

for (var i = 0, iLen = jqTds.length; i < iLen; i++) {
oTable.fnUpdate(aData[i], nRow, i, false);
}

oTable.fnDraw();
}
function reloadtable(id) {
oTable.fnDestroy();
$('#tblSubcategories').dataTable({
"sAjaxSource": '/wpadmin/Getsubgroups?category=' + id,

"aoColumnDefs": [{ "bSortable": false, "aTargets": ["actionlinks"] },{ "bVisible": false, "aTargets": [ "visible" ] }
]

});
}




[/code]
[quote]
Above is html and javascript code. In the page itself i am implementing inline edit with dropdown ,after edit in dropdown instead of value i need to display Text so i am calling ajax method to get text but now table rows are disorder due to hidden table header is there ,i want that column as hidden ,can any one help to solve this or link any code example of this type of application to learn.
[/quote]

Replies

  • suryasurya Posts: 8Questions: 0Answers: 0
    Anybody give the topic to learn in data table to resolve this issue
  • suryasurya Posts: 8Questions: 0Answers: 0
    Mr allan last time also you give me instruction a topic to solve previous problem can u inform this time also
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Please see http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Also, if you want to hide columns after initialisation, don't use the initialisation options (which are for initialisation time only), use the API ( fnSetColumnVis ).

    Allan
  • suryasurya Posts: 8Questions: 0Answers: 0
    Thank you allan, As i am in start-up company no time to read all the topics in datatable , i know datatable can solve any problem of mine, i will make time to read all the concepts, the problem is solved thanx again
This discussion has been closed.