Search not working on certain columns
Search not working on certain columns
Hello All,
Firstly, great work on the plug-in! Very easy to use and customise, love it!
I'm having a strange problem with my datatable. It used to have 7 columns at first but the requirement was to have more so added a few more. Search (server-side .net MVC) works perfectly fine on the existing columns but doesn't work on the newly added columns :( It is failing on the DatatablesHelper.cs' Parse() method.
I have looked through the HTTP Request params object and there isn't anything unusual there. The new columns are all of type "string" as everything else except the Updated Date (which I didn't think matters). There is nothing obviously wrong but somehow it feels like there is a datatable configuration that I'm missing!!
Any advice/help is much appreciated.
Firstly, great work on the plug-in! Very easy to use and customise, love it!
I'm having a strange problem with my datatable. It used to have 7 columns at first but the requirement was to have more so added a few more. Search (server-side .net MVC) works perfectly fine on the existing columns but doesn't work on the newly added columns :( It is failing on the DatatablesHelper.cs' Parse() method.
I have looked through the HTTP Request params object and there isn't anything unusual there. The new columns are all of type "string" as everything else except the Updated Date (which I didn't think matters). There is nothing obviously wrong but somehow it feels like there is a datatable configuration that I'm missing!!
Any advice/help is much appreciated.
This discussion has been closed.
Replies
[code]
var oTable;
var asInitVals = new Array();
/* POST data to server */
$(document).ready(function() {
oTable = $('#Itemstable').dataTable({
"aoColumns": [
{ "sClass": "no-wrap",
"fnRender": function(oObj) {
var nameToDisplay = oObj.aData[0];
var length = nameToDisplay.length;
if (length > 40) {
nameToDisplay = nameToDisplay.substring(0, 40) + "...";
}
return "" + nameToDisplay + "";
}
},
{ "bVisible": false },
null,
null,
{ "sClass": "no-wrap",
"fnRender": function(oObj) {
var nameToDisplay = oObj.aData[4];
var length = nameToDisplay.length;
if (length > 30) {
nameToDisplay = nameToDisplay.substring(0, 30) + "...";
}
return "" + nameToDisplay + "";
}
},
{ "sClass": "no-wrap",
"fnRender": function(oObj) {
var nameToDisplay = oObj.aData[5];
var length = nameToDisplay.length;
if (length > 30) {
nameToDisplay = nameToDisplay.substring(0, 30) + "...";
}
return "" + nameToDisplay + "";
}
},
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"sDom": '<"H"<"CreateItemContainer"><"SearchAllCodesContainer">f><"Scrolly"t><"F"ip<"ProcessingContainer"r>><"clear">',
// "bJQueryUI": true, //for themeroller
"iDisplayLength": 25,
// "sScrollX": "100%",
// "sScrollY": "50",
"bStateSave": true,
"bPaginate": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Item/DataTableData",
"aaSorting": [[7, "desc"]],
"fnInitComplete": function() {
var oSettings = this.fnSettings();
for (var i = 0; i < oSettings.aoPreSearchCols.length; i++) {
if (oSettings.aoPreSearchCols[i].sSearch.length > 0) {
$("thead input")[i].value = oSettings.aoPreSearchCols[i].sSearch;
$("thead input")[i].className = "";
}
}
},
"fnServerData": function(sSource, aoData, fnCallback) {
/* Add some extra data to the sender */
aoData.push({ "name": "pushedData", "value": "pushedValue" });
$.getJSON(sSource, aoData, function(json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
});
},
"iDisplayStart": 0,
"oLanguage": {
"sSearch": "Search all columns:"
}
});
$("thead input").keyup(function() {
/* Filter on the column (the index) of this element */
oTable.fnFilter(this.value, $("thead input").index(this));
});
$("thead input").each(function(i) {
asInitVals[i] = this.value;
});
$("thead input").focus(function() {
if (this.className == "search_init") {
//this.className = "";
this.value = "";
}
});
$("thead input").blur(function(i) {
if (this.value == "") {
this.className = "search_init";
this.value = asInitVals[$("thead input").index(this)];
}
});
});
[/code]