DHTMLX Grid Pulling Additional Data - javascript
I am trying to build an app for users to submit their work times in but am having trouble with pulling additional data into the grid.
Eg: If a user were to type in there employee code of 0000 into the Employee Code Column the Employee Name Field would need to update to read "John Doe" All this data is stored in databases on the back end and I have been able to access it on refresh eg. If the page is reloaded after the new row has been created and the data is present it will pull the correct data in, but i do not want them to have to refresh the page to do this. How can I pull in the extra data after the cell has been updated.
The Grid is created on the page with JavaScript as follows:
timesheetGrid.setColumnIds("Column Names, Column Names");
timesheetGrid.setImagePath("codebase/imgs/"); //set the image path for the grids icons
timesheetGrid.setInitWidths("70,100,100,100,70,100,150,100,70,70,100,70,70,*,*"); //sets the initial widths of columns
timesheetGrid.setColAlign("center,center,center,center,center,center,center,center,center,center,center,center,center,left,left"); //sets the alignment of columns
timesheetGrid.setColTypes("edn,ro,dhxCalendar,ro,edn,ro,ed,ro,ro,ro,ed,edn,ch,txt,ro"); //sets the types of columns
timesheetGrid.setColSorting("str,str,date,date,str,str,str,str,str,str,str,str,str,str,str"); //sets the sorting types of columns
timesheetGrid.setDateFormat("%Y-%m-%d"); //Set the Date Format to be used in the Grid
timesheetGrid.attachHeader("#text_filter,#text_filter,#text_filter,,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,,,");
timesheetGrid.setColumnHidden(3,true);
timesheetGrid.enableEditEvents(true,false,true);
timesheetGrid.init();
//timesheetGrid.makeFilter("WeekEnding",0); //TODO: Add Filter For Week Ending
//this.lockRow(id, true); //Make Specific Row Read Only TODO: Non Active Week Rows Read Only
timesheetGrid.load("data/timesheets.php");
var dpg = new dataProcessor("data/timesheets.php");
dpg.enableDataNames(true); // will use names instead of indexes
dpg.init(timesheetGrid);
PHP is used to pull data from the correct avenues
require("../codebase/connector/grid_connector.php");//adds the connector engine
$conn = new GridConnector($res,"MySQL"); //initializes the connector object
if ($conn->is_select_mode()) {//code for loading data
SQL Code is HERE
}else { //code for other operations - i.e. update/insert/delete
OTHER SQL CODE IS HERE
}
As the Data is sensitive I cannot display any of it sorry for any inconvenience.
Any Help would be much appreciated.
If the data you're providing is XML you can attach an event to your grid and call this grid.updateFromXML("data/timesheets.php");
This will parse and paint the whole grid information
If you're looking to update just the row you updated you can send via GET the id of the row and it will only parse and paint the row you're sending
grid.updateFromXML("data/timesheets.php?for=" + row_id));
Full Code would be something like this:
dpg.defineAction ("update", myUpdate);
function myUpdate(tag){
timesheetGrid.updateFromXML("data/timesheets.php?for="+tag.getAttribute("sid"));
return true;
}
If the data you're retrieving is not XML formatted, I'm afraid you would need to update the values from the row manually via the same event.
Related
Javascript/PHP - Get last post ID from livechat system
I am currently upgrading my livechat system to use the append function with JavaScript. And in order to get it to work I will need to get the latest chat date or ID somehow. So I can then do a query like: SELECT date, message, name FROM chat WHERE id > $lastPostId"; This will then allow me to append all the latest messages instead of updating all of the HTML everytime there is a new message So basically, my chat right now works like this: Every second it checks for my PHP file, loadchat.php. Loadchat.php will get every single message from the database It then replaces all current data in my div: #chatbox by using .html() function. And I want to change it to the append function in jquery allowing it to run a lot smoother Because it only needs to read everything the first time and then append So my question is, how do I get the last post ID?
Case 1: Add one more field in your database called timestamp. When you update the chat you can store the value of last timestamp in session.Now each time fetching a new chat just send that timestamp to loadchat.php and query the db to fetch rows where timestamp > stored_timestamp. Case 2: You can take a flag in db like is_read. When you insert the new chat the default value of is_read will be 0. When you fetch the data just update the flag i.e is_read = 1. Now in your query you just have to check for the flag. where is_read = 0. It will fetch all the unread messages and will do the job. Hope it will help!!
Google Sheets/JIRA Connection
I'm trying to connect Google Sheets to JIRA to gather the data for updating reports automatically. I'm struggling however with a couple of points in this modified script. I want to return the component field but calling the name field returns undefined. var components = data["issues"][id].fields.components.name; If I remove the name field, then I get the following response: {name=#####, self=https://www.#########/rest/api/2/component/26357, id=26357} The second issue is that only a handful of issues are being rendered. As far as I can see my REST call looks OK, as does the writing to tables: var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); //select active spreadsheet sheet.getRange(2, 1, issuessss.length, 7).setValues(issuessss); // write from cell A2 break; Anyone have any ideas that could help?
The field component is an array so components.name does not exist (i.e components[0].name would work). Before setting the values, try to execute a flush first.
Lightswitch load all data or run a async method synchronously
I have a grid with data in Lighswitch application. Grid has on every column posibility to filter column. Thanks to lsEnhancedTable Right now I am sending an ajax request to the web api controler with the list of ids of the Customers that I want to export. It works but with a lot of data it is very slow because I have to turn off the paging of the data to get all visible customers ids so I can iterate over the VisualCollection. To optimize this I would have to turn on back the paging of the data to 50 records so that the initial load is fast and move the loading of the data to a save/export to excel button. Possible solutions: Load data all data on save button click. To do this I have to somehow load all items before I can iterate over collection. The code bellow locks UI thread since the loadMore is async. How to load all data synchronously? Ideally I would like to have some kind of progress view using a msls.showProgress. while(3<4) { if (screen.tblCustomers.canLoadMore) { screen.tblCustomers.loadMore(); } else break; } var visibleItemsIds = msls.iterate(screen.tblCustomers.data) .where(function (c) { return c; }) Second approach would be turn on paging and pass just the filters applied by the users to the web api controller so I can query database and return only filtered records. But I don't know how to do that. Third approach is the one that I am using right now. Turn off the paging->iterate over visual collection, get the customers id, pass them to the controller and return a filtered excel. This doesn't work well when there are a lot of records. Iterate over filtered collection in the server side? I don't know if there is a way to do this in Lighswitch?
Here's an option for client side javascript. // First build the OData filter string. var filter = "(FieldName eq " + msls._toODataString("value", ":String") + ")"; // Then query the database. myapp.activeDataWorkspace.ApplicationData.[TableName].filter(filter).execute().then(function (result) { ... });
Datatable client-side data change/redraw
I set up a datatables that initially gets from server some data and represents it, but then everything is left to the client. Some options are: serverSide: false, sAjaxSource: mySource, My $.fn.DataTable.version is 1.10.2. Then I need to change, client-side, the aaData under the table because some working on data is performed. I need to update the DT to show the client-altered temporary data without send another request to server (for two reason: prevent useless traffic and because that data is being altered). I am looking for a way to edit the underlying DT databean to edit it, so then calling again myTable.draw(); on my table I obtain a refresh realtime without sending another get to the server. The question is, can I access DT data array, and can I edit it? How is it done if is possible? EDIT: I need to feed the table the full bean array as it initially took from the server, same format. So individual row/cell add/edit and client-side building functions are not suitable in my case, unless I manually cicle all objects.
SOLUTION Use the code below: // Retrieve data var data = table.ajax.json(); // Modify data $.each(data.data, function(){ this[0] = 'John Smith'; }); // Clear table table.clear(); // Add updated data table.rows.add(data.data); // Redraw table table.draw(); DEMO See this jsFiddle for code and demonstration.
sencha extjs data in multiple referenced grids
I have two grids getting data from php mysql backend First grid is display of all classes in a school. This represents 1 table of mysql. And I have no issues in displaying data second grid gets data of students in a particular class, when one clicks on any of the class of first grid. Please see image below This is a different table in mysql. And I am "ClassID" to php file. which sends sorted JSON of students of that particular class i use the below code var studentView = this.getstudentGrid; var ClassData = record.get('ClassID'); studentView.getStore().load({ params:{ClassID: ClassData} }); but it says uncaught error and nothing gets displayed. Kindly help