selection list filtering in datatables (MVC 3) with javascripthttp://forums.asp.net/t/1800054.aspx/1?selection+list+filtering+in+datatables+MVC+3+with+javascriptMon, 07 May 2012 09:12:30 -040018000544965313http://forums.asp.net/p/1800054/4965313.aspx/1?selection+list+filtering+in+datatables+MVC+3+with+javascriptselection list filtering in datatables (MVC 3) with javascript <p>I have a problem trying to show a list of elements to a filter in a&nbsp;<a href="http://datatables.net/" rel="nofollow">datatables</a>.</p> <p>I follow&nbsp;<a href="http://gunbladeiv.blogspot.com.es/2011/06/part-2-mvc-3-and-datatables-with-inline.html" rel="nofollow">this tutorial</a>&nbsp;and try to make a filtering records in a datatable.</p> <p>This is the code to return list in my controller:</p> <pre class="prettyprint">public JsonResult grupMonedas() { IList&lt;MONEDA&gt; temp = (from c in db.MONEDA select c).ToList(); var result = from c in temp select new [] { c.NOMBREMONEDA }; return Json(result); }</pre> <p>And this is my javascript to make the data table and the filters:</p> <pre class="prettyprint">&#36;(document).ready(function () { //Nombre en la tabla donde se ejecutara var oCuentas = &#36;('#tablaCuentas').dataTable({ //Es el que emplementa para trabajar con la pagina "bServerSide": true, //Metodo el qual se ejecutara "sAjaxSource": "Cuentas/CargarCuentas", //Mensaje cargado "bProcessing": true, "bJQueryUI": true, //Columnas que cargara "aoColumns": [ //Las columnas tienen que coincidir con la base de datos {"sName": "NUMCUENTA" }, { "sName": "NOMBRECUENTA" }, { "sName": "SALDO" }, { "sName": "Moneda" } ], //Mostrar Diferentes opciones "bPaginate": true, "bLengthChange": true, "bFilter": true, "bSort": true, "bInfo": true, "bAutoWidth": true }).columnFilter({ "aoColumns": [ { sSelector: "#numeroFiltro", type: "number" }, { sSelector: "#nombreFiltro", type: "text" }, { sSelector: "#saldoFiltro", type: "number-range" }, { sSelector: "#monedaFiltro", type: "select", values: grupMonedas() } ] }); }); function validateJSON(x) { var orig = x; var stgify = JSON.stringify(orig); var splitchar = ['\\"', '\',\'', '[', ']', '\"']; var joinchar = ['\'', '\':\'', '', '', '']; for (i = 0; i &lt; 5; i++) { stgify = stgify.split(splitchar[i]); tmp = stgify.join(joinchar[i]); stgify = tmp; } stgify = "[" + stgify + "]"; var finalEdit = stgify; //alert(finalEdit); &lt;- returns a ok list of elements :S return finalEdit; } function grupMonedas() { &#36;.post('Cuentas/grupMonedas', {}, function (data) { grupMonedas = validateJSON(data); }, 'json/javascript' ); return grupMonedas; }</pre> <p>But in the filter of select &quot;Moneda&quot; just put a &quot;title&quot; and nothing more, no the elements created in the list.</p> <p>Thanks in advance.</p> <p>PS: Sorry for my English</p> 2012-05-04T09:44:25-04:004968687http://forums.asp.net/p/1800054/4968687.aspx/1?Re+selection+list+filtering+in+datatables+MVC+3+with+javascriptRe: selection list filtering in datatables (MVC 3) with javascript <p>All your code seems to be OK. Probably we wil try making little modifications and see if things get working.</p> <p>Controller</p> <pre class="prettyprint">public JsonResult grupMonedas() { var temp = db.MONEDA.SelectMany(c=&gt;c.NOMBREMONEDA); return Json(temp.ToList()); //you can try using temp.ToArray() too }</pre> <p>Now in you view</p> <pre class="prettyprint">function grupMonedas() { &#36;.post('Cuentas/grupMonedas', function (data) { grupMonedas = data; },&quot;json&quot;); return grupMonedas; }</pre> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Rassell</h4> <p></p> <pre class="prettyprint">.columnFilter({ &quot;aoColumns&quot;: [ { sSelector: &quot;#numeroFiltro&quot;, type: &quot;number&quot; }, { sSelector: &quot;#nombreFiltro&quot;, type: &quot;text&quot; },</pre> <p></p> </blockquote> <p></p> <p>also remove the quotes around &quot;aoColumns&quot;, i am not sure thought. Just refer to the below link for the exact syntax for datatable</p> <p><a href="http://jquery-datatables-column-filter.googlecode.com/svn/trunk/customFilters.html">http://jquery-datatables-column-filter.googlecode.com/svn/trunk/customFilters.html</a><br> <br> <br> </p> 2012-05-07T09:12:30-04:00