fixing bug for list display -- sort by note count now working
authorCharles Holbrow <charlesholbrow@gmail.com>
Mon, 18 Mar 2013 22:57:58 +0000 (18:57 -0400)
committerCharles Holbrow <charlesholbrow@gmail.com>
Mon, 18 Mar 2013 22:57:58 +0000 (18:57 -0400)
karmaworld/templates/courses/course_list.html

index a3e3da0c78a2fdafcbd4d6aca3fa12729021a1bf..9798c47863af02043a6340c3357bfe925d8097e5 100644 (file)
@@ -39,16 +39,29 @@ $(document).ready(function() {
       null,
       null, 
     ],
-    // Add the 'Notes' label string to the notes row
-    'fnRowCallback': function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
-      $('td:eq(2)', nRow).append(' Notes');
-    },
+    "aoColumnDefs": [ {
+      "aTargets": [ 2 ],
+      "mData": function ( source, type, val ) {
+        //console.log(source);
+        if (type === 'set') {
+          source.count = val;
+          // Store the computed dislay and filter values for efficiency
+          source.count_display = val=="" ? "" : val+" Notes";
+          return;
+        }
+        else if (type === 'display') {
+          return source.count_display;
+        }
+        // 'sort', 'type', 'filter' and undefined all just use the integer
+        return source.count;
+      }
+    } ],
     // Initial sorting
     'aaSorting': [[2,'desc']]
     // Use out Ajax endpoing to populate the list
     //'sAjaxSource': "{% url 'api_course_list' %}" 
   });
-$('.dataTables_filter input').attr("placeholder", "search courses");
+  $('.dataTables_filter input').attr("placeholder", "search courses");
 });
 </script>
 {% endblock %}