I can't manage to put this JSON data inside DataTables - javascript
So, the situation is this. There is a HTML page with a table in it, that is using the DataTables plugin. I have to show data that I'm receiving from a jQuery POST call in the table, but I always seem to get errors and am lost in how to go about doing that.
This is what the response from the POST call looks like:
[{"idoperatore":10,"nome_cognome":"Daniele Torrini","tariffa_esterno":"50.00","tariffa_interno":"0.00","tariffa_viaggio":"30.00","idtariffa_esterno":11,"idtariffa_interno":16,"idtariffa_viaggio":13,"attivo":1,"rs":0,"iniziali":"DT"},{"idoperatore":12,"nome_cognome":"Irene Cavalletto","tariffa_esterno":"75.00","tariffa_interno":"45.00","tariffa_viaggio":"30.00","idtariffa_esterno":9,"idtariffa_interno":15,"idtariffa_viaggio":13,"attivo":1,"rs":1,"iniziali":"IC"},{"idoperatore":14,"nome_cognome":"Sandra Moschetti","tariffa_esterno":"50.00","tariffa_interno":"0.00","tariffa_viaggio":"30.00","idtariffa_esterno":11,"idtariffa_interno":16,"idtariffa_viaggio":13,"attivo":1,"rs":0,"iniziali":"SM"},{"idoperatore":15,"nome_cognome":"Federica Coucourde","tariffa_esterno":"90.00","tariffa_interno":"0.00","tariffa_viaggio":"30.00","idtariffa_esterno":8,"idtariffa_interno":16,"idtariffa_viaggio":13,"attivo":1,"rs":0,"iniziali":"FC"},{"idoperatore":16,"nome_cognome":"Matteo Belgero","tariffa_esterno":"75.00","tariffa_interno":"0.00","tariffa_viaggio":"30.00","idtariffa_esterno":9,"idtariffa_interno":16,"idtariffa_viaggio":13,"attivo":1,"rs":0,"iniziali":"MB"},{"idoperatore":17,"nome_cognome":"Luca Belgero","tariffa_esterno":"90.00","tariffa_interno":"0.00","tariffa_viaggio":"30.00","idtariffa_esterno":8,"idtariffa_interno":16,"idtariffa_viaggio":13,"attivo":1,"rs":0,"iniziali":"LB"},{"idoperatore":18,"nome_cognome":"Federico Bottoni","tariffa_esterno":"50.00","tariffa_interno":"0.00","tariffa_viaggio":"30.00","idtariffa_esterno":11,"idtariffa_interno":16,"idtariffa_viaggio":13,"attivo":1,"rs":0,"iniziali":"FB"},{"idoperatore":19,"nome_cognome":"Giuseppe Pantaleo","tariffa_esterno":"60.00","tariffa_interno":"0.00","tariffa_viaggio":"30.00","idtariffa_esterno":10,"idtariffa_interno":16,"idtariffa_viaggio":13,"attivo":1,"rs":0,"iniziali":"GP"},{"idoperatore":20,"nome_cognome":"Matteo Ferrario","tariffa_esterno":"90.00","tariffa_interno":"75.00","tariffa_viaggio":"30.00","idtariffa_esterno":8,"idtariffa_interno":9,"idtariffa_viaggio":13,"attivo":1,"rs":1,"iniziali":"MF"},{"idoperatore":21,"nome_cognome":"Alessandro Mazzeranghi","tariffa_esterno":"100.00","tariffa_interno":"0.00","tariffa_viaggio":"30.00","idtariffa_esterno":7,"idtariffa_interno":16,"idtariffa_viaggio":13,"attivo":1,"rs":0,"iniziali":"AM"}]
I have no way of modifying the call, I have to work with that. I just have access to the variable that contains that response from the callback, but I can however transform or modify that data if needed.
This is what the HTML table looks like:
<table class="display nowrap" id="table_operatori">
<thead>
<tr>
<th>
<span></span>
</th>
<th class="mdl-data-table__cell--non-numeric">Nome e Cognome</th>
<th>Tariffa Esterno</th>
<th>Tariffa Interno</th>
<th>Tariffa Viaggio</th>
<th>Attivo?</th>
<th>RS?</th>
<th class="mdl-data-table__cell--non-numeric">Iniziali</th>
</tr>
</thead>
<tbody id="table_operatori_tbody">
</tbody>
</table>
There are not the same number of columns in the table as fields in the JSON because the fields in JSON starting with "id" have to be hidden values, and were used before as attributes of the HTML elements, to use them in later moments. It's also the reason for the empty header: the table was actually filled with pure HTML before, and had a checkbox in front to select the row, like this:
data.forEach(function (element) {
element["attivo"] == "1" ? element["attivo"] = "Si" : element["attivo"] = "No";
element["rs"] == "1" ? element["rs"] = "Si" : element["rs"] = "No";
var i = element['idoperatore'];
var tableRow = '<tr><td><label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-data-table__select" for="table_operatori_checkbox_row[' + i + ']"><input type="checkbox" id="table_operatori_checkbox_row[' + i + ']" class="mdl-checkbox__input" onClick="fOperatore_Checkbox_SelectUnique(' + i + ')" /></label></td>'
tableRow += '<td class="mdl-data-table__cell--non-numeric" id="table_operatori_nomecognome_row[' + i + ']">' + element['nome_cognome'] + '</td>';
tableRow += '<td id="table_operatori_tariffaesterno_row[' + i + ']" idtariffa="' + element["idtariffa_esterno"] + '">' + element['tariffa_esterno'] + '</td>';
tableRow += '<td id="table_operatori_tariffainterno_row[' + i + ']" idtariffa="' + element["idtariffa_interno"] + '">' + element['tariffa_interno'] + '</td>';
tableRow += '<td id="table_operatori_tariffaviaggio_row[' + i + ']" idtariffa="' + element["idtariffa_viaggio"] + '">' + element['tariffa_viaggio'] + '</td>';
tableRow += '<td id="table_operatori_attivo_row[' + i + ']">' + element['attivo'] + '</td>';
tableRow += '<td id="table_operatori_rs_row[' + i + ']">' + element['rs'] + '</td>';
tableRow += '<td class="mdl-data-table__cell--non-numeric" id="table_operatori_iniziali_row[' + i + ']">' + element['iniziali'] + '</td></tr>';
$("#table_operatori_tbody").append(tableRow);
This worked, in a sense, (apart from being extremely ugly) meaning that the table formed and you could select rows like we wanted and act on those later. But you couldn't sort, or filter with search, any of the rows in the table.
Still, I was willing to maintain the ugly HTML building if it meant getting the DataTable to work, since with .row.add() you can add a element, I tried that as well, changing the .append(tableRow) with:
.DataTable().row.add($.parseHTML(tableRow));
This didn't work either, and gave the same error. Also displayed this on the table though: Displays object picture
At the moment of initialization, I don't have the data to put inside the table. The table has to be initialized empty, and rows from the response added at a later time. I tried (with "data" being the variable containing the response from the server):
$("#table_operatori").DataTable().rows.add(data);
Which would remove a lot of the ugly HTML building, but it gives error:
DataTables warning: table id=table_operatori - Requested unknown parameter '1' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4
So, by looking at that tech-notes link, it says that it may be that you have more columns in the table head than in the table body, so I matched exactly the fields that I get, when defining the table, thinking that I may eventually be able to hide the columns that I don't need if that works.
$("#table_offerte").DataTable({
paging: false,
info: false,
columns: [
{ title: "idoperatore" },
{ title: "nome_cognome" },
{ title: "tariffa_esterno" },
{ title: "tariffa_interno" },
{ title: "tariffa_viaggio" },
{ title: "idtariffa_esterno" },
{ title: "idtariffa_interno" },
{ title: "idtariffa_viaggio" },
{ title: "attivo" },
{ title: "rs" },
{ title: "iniziali" }
]
});
But it still gives the same error. It also does if I match the table structure with the DataTable initialization :
columns: [
{ title: "idoperatore" },
{ title: "nome_cognome" },
{ title: "tariffa_esterno" },
{ title: "tariffa_interno" },
{ title: "tariffa_viaggio" },
{ title: "attivo" },
{ title: "rs" },
{ title: "iniziali" }
]
Documentation from DataTables also says that it looks inside a data: property when looking at JSON data, and you have to specify if it is not an object but an array by setting an empty string in the dataSrc property:
DataTable({ ajax: { url: "something.json", dataSrc: "" } });
The problem is that it requires the data being requested by the url: property, and I cannot do that, because I only have the "data" variable which contains the JSON.
I should also mention that by maintaining the old HTML building and appending it inside the table body, makes the table work and display stuff right, like this, but of course as soon as you try to sort or filter anything, it all disappears because the DataTable doesn't ACTUALLY have the rows inside it, just the HTML does.
I have no idea how to get this data in there. I hope I explained everything clearly, otherwise feel free to ask anything and I will try my best to clarify.
Thanks in advance for any help.
The doc is a bit confusing, because there are so many different ways to set up a table, and it's pretty much one guy (Allan Jardine) both writing the plugin and documenting it.
First, you don't need any table headers. Change your HTML to this:
<table class="display nowrap" id="table_operatori"></table>
If you want to add ids or classes to tbody tags, then you'll need to add them in as well. But to start, this is all the HTML you need.
What's confusing here is that a lot of Allan's examples include the data hard-coded into the HTML, with no JSON or AJAX or anything involved. When you do that, then you do need to set up the HTML headers, and all the cells, and everything else. Take a look at the HTML in one of his examples (this one, for example) and see this for yourself. And then, when he moves on to JSON examples, he pulls the data but he leaves the headers in. And again, you can put them in, but don't have to.
Rather, if you're pulling your data from JSON, you can either specify your headers with HTML th tags or you can do it with the columns (or colDefs) option. You don't need to do both. This isn't as clear from the doc as it might be, since in most of the examples Allan does do both.
Whichever way you specify the headers, they have to match the column count of the JSON feed. If they don't, you'll get some form of the error you're getting. Furthermore, if you use both column and th, they both have to match your JSON field count or you'll get that error. That's why you're getting your error. You matched your columns definition correctly, but you've left some th tags out in your table definition. The solution is to remove the th tags entirely.
I'm going to presume that the reason that you left out some th tags is that you are under the impression that that's the way to make the column invisible. It isn't, for the reasons I've described above. The easiest way to define whether a column is visible or not (as well as define a lot of other possible attributes, listed here) is in your columns array: just set the column's visible option to false. (You could also use th tags with a class and set visibility:none in CSS, but this is simpler. Less to keep track of.)
Also, the title value on a column is the value for title in your columns array for that column. So, you need to make it look the way you want it, not put the name of your JSON field there.
Finally, with the data option, you're reading the wrong part of the documentation, which is about how to pull JSON from a URL using AJAX at the time you run dataTable(). You have the data already in your POST data, so you don't need to do that. So, read this instead. Have a look at the second example, which shows an array of objects as a data source. From what I see of your JSON string, you should just have to add an option like this:
data: myPOSTResponse,
Putting all that together:
$("#table_offerte").DataTable({
paging: false,
info: false,
data: myPOSTResponse,
columns: [
{ visible: false }, //this is the ID you don't want to see, no need to give it a title
{ title: "Nome e Cognome", className: "mdl-data-table__cell--non-numeric" },
{ title: "Tariffa Esterno" },
{ title: "Tariffa Interno" },
{ title: "Tariffa Viaggio" },
{ visible: false },
{ visible: false },
{ visible: false },
{ title: "Attivo?" },
{ title: "RS?" },
{ title: "Iniziali", className: "mdl-data-table__cell--non-numeric" }
]
});
That should get you running, if you haven't done something else interesting. :)
Edit: as DocCobra mentions in the comments, you also have to specify the data: option at the field level here, since the array elements are objects. If they are themselves arrays, you do not.
Related
how to Disable / Enable button in datatable
I want to check the Article's Status, if true the Edit button will be disabled else the user can click and switch to the Edit page. How to use it? return ' Edit '; }} ], order: [1, 'asc'] });
The column render function you are using: render: function (data) { ... } is capable of accessing all the data in the current row. Its full signature is: render: function ( data, type, row, meta ) { ... } So, you can use the row parameter to access other columns in that row, such as row.status: { data: 'id', className: "center", title: 'Actions', render: function (data, type, row, meta) { if (row.status === true) { return ' Edit '; } else { return '<a href="Student/EditArticle/' + data + '" class="btn btn-success mr-1" disabled> Edit </a>'; } } } You can see further details and examples here. It is worth looking at why the type parameter is provided and how it is used. It basically helps you to provide multiple versions of a value - one value for the table display (the HTML link); a different value for sorting; another value for filtering, and so on. So, for example, for your clickable link, you may prefer the sort and filter values to be simply the data value (without any of the extraneous HTML). But this is completely optional - you don't have to use it. See orthogonal data for more info. Update: I forgot that a hyperlink cannot be disabled in the same way as a button (so you cannot use "disabled"). Instead, you can look at these approaches, or do what TimRoberts suggested in your question's comments. Having said that, the render function with the row parameter should be what you need. else { return 'Edit'; // or, alternatively: return '' }
How do I add a radio button to HTML table via jquery
I'm using Jquery $.post to get string array from SQL based on selection from a drop-down that I'm then reading into an HTML table. Each time they change selection on drop down, it clears all but the header row from the table and reloads new values. That is working fine. It is just a basic 3 row table; a unique identifier, a value and a count shown as string. Every record has all 3, so I'm just using for loop with counters to control start/end of rows. In my form it's header is defined as such: <div class="col-md-10"> <table id="attEditTable" style="width:100%" cellpadding="0" cellspacing="0" border="1" class="row"> <tbody> <tr style="background-color: #F0F8FF;"> <th></th> <th>Attribute Value</th> <th>Item Count</th> </tr> </tbody> </table> </div> I'm now trying to change the 1st cell of each row to a radio button with the value set to the value I was displaying in that cell. Currently when the view displayed it is showing [object Object] in the first cell of every row instead of a radio button. Sorry I am a newb at this with no training on Java or MVC - so hoping just a simple syntax issue... Trying this basic one returned syntax error on input: <input type="radio" name="SelERow" value='+editValues[i]+' /> I've also tried (both had same result of [object Object]): $("input:radio[name=\"SelERow\"][value="+editValues[i]+"]") $('<input type="radio" id="ERow" name="SelERow" value='+editValues[i]+' />') Per David's suggestions I've now also tried (both resulted in no data and no error): '<input type="radio" name="SelERow" value='+editValues[i]+' />' var tblCell = $('<td />'); // create an empty <td> node if (x == 1 || (x - 1) % 3 == 0) { var input = $('<input />', { type: 'radio', id: 'ERow', name: 'SelERow', value: editValues[i] }); tblCell.append(input); // append an <input> node to the <td> node } else { tblCell.text(editValues[i]); // or just set the text of the <td> node } With the 2nd one I also changed the line: tblRow = tblRow + ""; to instead be tblRow = tblRow + tblCell + ""; Current Script <script> $(function () { $("#EditAttributeName").change(function () { var selectedName = $(this).val(); // Delete all but first row of table $("#attEditTable").find($("tr")).slice(1).remove(); var url2 = "EditDD2changed?selectedName=" + selectedName; $.post(url2, function (editValues) { var x = 0; var tblRow = "<tr>"; for (var i=0; i < editValues.length; i++) { x++; if (x == 1 || (x - 1) % 3 == 0) { tblRow = tblRow + "<td>" + $('input:radio[name="SelERow"][value="' + editValues[i] + '"]'); } else { tblRow = tblRow + "<td>" + editValues[i] + "</td>"; } if (x % 3 == 0) { tblRow = tblRow + "</tr>"; $("#attEditTable").append(tblRow); tblRow = "<tr>"; } } }) }); }); </script> Console is showing no error messages.
Looks like it's close. To start, there's an important difference in the two attempts. This is a jQuery selector syntax: $('input:radio[name="SelERow"][value="' + editValues[i] + '"]') So it's not creating an <input/>, but looking for an <input/>. Which isn't what you want in this case. Your other attempt uses the syntax for creating an element: $('<input type="radio" id="ERow" name="SelERow" value=editValues[i] />') Though an issue here (which may have just been a copy/paste error in posting the question? but for completeness and for future readers it may as well be addressed...) appears to be that the editValues[i] is just part of the string. You want to concatenate it into the string. There are a couple ways to do that. Either direct concatenation: $('<input type="radio" id="ERow" name="SelERow" value="' + editValues[i] + '" />') Or string interpolation (take note of the different overall quotes, using back-ticks this time): $(`<input type="radio" id="ERow" name="SelERow" value="${editValues[i]}" />`) The latter is newer syntax but should be widely enough supported by now. (Though in any given business environment who knows what ancient browsers one may need to support.) Could just be personal preference between the two. it is showing [object Object] The main issue producing the result you've observing is that you're concatenating the result of that jQuery operation directly as a string: tblRow + "<td>" + $('<input type="radio" id="ERow" name="SelERow" value="' + editValues[i] + '" />') (Coincidentally, whether you're creating an element or looking for an element, this observed output would be the same because both operations return an object.) The result of an $() operation is not itself a string, but a more complex object. When concatenated with a string it has to be interpreted as a string, and unless the object has a meaningful .toString() implementation (this one doesn't appear to) then the default string representation of a complex object is exactly that: "[object Object]" There are a couple approaches you can take here. One would be to just use strings entirely, you don't necessarily need a jQuery object here: tblRow + '<td><input type="radio" id="ERow" name="SelERow" value="' + editValues[i] + '" /></td>' Since you're using jQuery later to append the result to the HTML, you can just build up all the HTML you like as plain strings and let jQuery handle turning them into DOM objects when you send them to .append(). The other option, if you definitely want to "use jQuery" in this situation or are otherwise being instructed to, would be to build the hierarchy of HTML elements as jQuery objects and then pass that hierarchy to .append(). Constructing such a hierarchy can look something like this: var tblCell = $('<td />'); // create an empty <td> node if (x == 1 || (x - 1) % 3 == 0) { var input = $('<input />', { type: 'radio', id: 'ERow', name: 'SelERow', value: editValues[i] }); tblCell.append(input); // append an <input> node to the <td> node } else { tblCell.text(editValues[i]); // or just set the text of the <td> node } Note that each $() operation creates an HTML element node, and you can supply attributes for it as a second argument to the $() function. Then those nodes can be .append()-ed to each other just like you .append() the HTML string to $("#attEditTable"). In your particular case this may get a little more cumbersome because your loop isn't just looping through cells or just through rows, but through both and using a hard-coded count to determine whether it's reached the end of a row or not. So, as part of learning/practicing jQuery, it may be worth the effort to try this approach. But I suspect the shortest path to getting your code working with minimal changes would be the string concatenation approach above. Side note: This code is using the same id value for the radio buttons created within this loop. The result is that there is expected to be multiple elements on the page with the same id. This is technically invalid HTML. If you ever try to use that id to reference an element, the resulting behavior will be undefined. (It might work in some cases, might not in others, purely coincidentally.) Though if you don't need to use that id to reference the elements, you may as well remove it entirely.
Extjs how to get specify element after render in grid panel
Hi I know this issue title is a little blurred. I have a grid column and want to implement data rating. I use renderer and return div but now I have no idea to get the elements. My code is as below { text: 'rank', dataIndex: 'rank', flex: 1, tdCls: 'column-rank', renderer: function(value) { return '<div class=rating>' + '<div data-rating="1"></div>' + '<div data-rating="2"></div>' + '<div data-rating="3"></div>' + '<div data-rating="4"></div>' + '<div data-rating="5"></div>' + '</div>' } }
I guess you have to take a look at rating widget as CD mentioned. If you still want to implement rating on your own I guess you have to write custom component for it, setup it with rating data from grids store and reference to a certain row in renderer. If you still want to implement rating on your own using divs you can do something like this to select data-rating divs: Ext.query('div[data-rating="5"]', myRowComponent.getEl());
renderer function is passed several parameters when called. One of them, as stated in the documentation is record. You can use this parameter to extract record for the current row. You can access record fields just as you access model fields record.get('fieldName'). Example pseudo-code: renderer: function(value, metaData, record, rowIndex, colIndex) { var fieldValue1 = record.get('fieldName1'); return '<div class=rating>' + '<div data-rating="1">' + fieldValue1 + '</div>' + ... '</div>'; }
Dynamic jQuery Dialog passing JSON object from within loop
I'm wondering if there is a better (cleaner?) method than my current implementation. I'm currently encoding a PHP SimpleXMLObject (USPS Tracking API) to JSON and looping through said JSON object via Javascript to operate the front-end. Examples from my current implementation below: Function to display dialog implemented anonymously outside of .ready() : var moreInfo_popup = function(i) { $('#moreinfo'+i).dialog({ modal:false, autoOpen:false, height:555, title: 'Detailed View', width:500, draggable:false, buttons: { Ok: function(){ $(this).dialog("close"); } } }); $('#moreinfo'+i).dialog('open'); } Main loop for displaying Tracking ID, Most Recent Event, and Mail Class for each API response- I'm currently generating a content div appended to #modal_container, then calling moreInfo_popup() inline via <input onClick="">: for(var key in obj) { if(obj.hasOwnProperty(key)) { if(key % 2 === 0) { $('#page-nav').append("<div id=\"results_table\"><table class=\"data_table\"id=\"data_table_id\"border=\"0\"width=\"60%\"align=\"center\"><tr><td align=center width=20%>"+obj[key].TrackInfo.Attributes.ID+"</td><td align=\"center\"width=\"35%\">"+obj[key].TrackInfo.StatusSummary+"</td><td align=\"center\"width=\"20%\">"+obj[key].TrackInfo.Class+"</td><td align=\"center\"><input type=\"button\"class=\"moreInfo\"value=\"Detail\"id=\"_buttonMoreInfo\"onClick=\"moreInfo_popup("+key+")\"></td></tr></table></div>"); $('#modal_container').append("<div id=\"moreinfo" + key + "\"><table><tr><td>" + obj[key].TrackInfo.Attributes.ID +"</td></tr></table>").hide(); } else { $('#page-nav').append("<div id=\"results_table\"><table class=\"data_table_even\" id=\"data_table_id\" border=0 width=60% align=center><tr><td align=center width=20%>" + obj[key].TrackInfo.Attributes.ID + "</td><td align=center width=35%>" + obj[key].TrackInfo.StatusSummary + "</td><td align=center width=20%>" + obj[key].TrackInfo.Class + "</td><td align=\"center\"><input type=\"button\" value=\"Detail\" class=\"moreInfo\" id=\"_buttonMoreInfo\"onClick=\"moreInfo_popup("+key+")\"></td></tr></table></div>"); $('#modal_container').append("<div id=\"moreinfo" + key + "\"><table><tr><td>" + obj[key].TrackInfo.Attributes.ID +"</td></tr><tr><td> <button>OK</button></td></tr></table>"); } } $("#page-nav td:contains('undefined')").html("Invalid"); } As I'm sure you can see, this feels like an incredibly tedious way of accomplishing the desired outcome, to which there is surely a better alternative. As a newcomer to JavaScript/jQuery, I've done plenty of searching on this subject, but haven't really understood much of what I found- If indeed I was asking the right questions in the first place.
I think you can use angular and data bind: So you can just use a directive and automatically bind your JSON object from the server side easily to the html elements. However you should start studying angular. you can start looking for your elegant way of doing stuffs here: https://docs.angularjs.org/tutorial/step_04 I hope it was useful.
How to Add a Drop Down List in a Kendo UI Grid
Using Kendo UI and a Row Template, I have a grid started like the following: http://jsfiddle.net/xF4CK/ I'm wanting to alter the Actions column to contain a drop down list populated by the actions object. The actions object contains display text and a relative url path like the following example: var actions = [ { name: "edit", url: "reports/report/1" }, { name: "delete", url: "reports/delete/1" } ]; This actions object is on each row of the grid and may vary per row/user/etc. The intended usage would be a user selects the drop down list and then chooses one of the options. On choosing the option the url value is posted. I'm not sure where to begin, or if it is possible in the Row Template. Any help is greatly appreciated.
I was able to get it figured out. In the row template I am calling a js function and returning html markup for the list. Then setting the .kendoDropDownList on all items based on a class attribute. I have updated the jsfiddle here but it doesn't seem to work in jsfiddle. It is working when I test in IE10 and Chrome on my dev machine. Here's the relevant code changes: In the rowTemplate, changed #: actions # to #= renderDropDown(actions) # This "=" displays the literal text which renders the html as html whereas the ":" encodes the html. The renderDropDown function: function renderDropDown(actions) { var dropDownList = "<select class=\"insight-dropdown\">"; dropDownList = dropDownList + "<option value=\"default\" disable=\"disabled\">...</option>"; for (var i = 0; i < actions.length; i++) { dropDownList = dropDownList + "<option value=\"" + actions[i].url + "\">" + actions[i].name + "</option>"; } dropDownList = dropDownList + "</select>"; return dropDownList; } To the dataBound event of the grid, I added this function to turn the html into a drop down list: // Set the drop down lists $(".insight-dropdown").kendoDropDownList({ select: onDDLSelect }); To handle the selection of an action: function onDDLSelect(e) { var dataItem = this.dataItem(e.item.index()); alert(dataItem.value); }