get data from main grid to populate subgrid - javascript

I need to populate my subgrid which shows some of the columns from main grid without actually going and getting data again using URL? Example:Main Grid is getting data from server (10 columns) using jsonReader. Out of which I want to show 7 columns in the parent row and 3 columns in the subgrid row . Can I do this? (Or some other way to achieve this expand concept?)

One possible workaround to use the sub-grid as 1-1 with main grid, instead of as parent-child : query all the columns as normal in the parent grid, but set the ones you don't want in main row as hidden. Then in sub-grid load event, access those fields using the "parent" row id and create them as custom fields or simply emit custom html.
This does cause duplication of the fields though, since the original main grid fields are still present, even if hidden. The html ids will get duplicated and may cause conflicts if you don't handle them.
Perhaps there is a cleaner way to do it than this (which I'm sure #Oleg will show us any minute now!)
But I wish jqgrid had a documented feature to more easily handle this kind of thing. It is very useful because you get the benefit of full inline editing in the subgrid, so you can design a much nicer edit form (eg. multiline textareas) than when confined to one straight line.
Note the presence of this feature in other grids.
Jquery EasyUI Datagrid demo
Telerik Grid Editing Demo

Related

Table Sorting, Filtering, Etc Matt Kruse's library

Situation:
I'm playing a little by using the Matt Kruse's library I found at the page Table Sorting, Filtering, Etc at the URL http://javascripttoolbox.com/lib/table/source.php.
It works pretty well but I wish to implement a little improvement (maybe it would be better to use the locution "new feature") and I don't know where to start because I'm a newbie in js and that js file uses more advanced programming statements I don't fully understand, not yet at least.
I have a single html file with some tables in it. Some of them are filterable and sortable thanks to that library. The number of tables may vary, the number of columns (fields) in each table may vary as well, and the number of records (rows) of each table may vary as well too. Of course the content is different in each table too.
By placing a specific css class in the th element of the targeted column I choose, I indicate to the Matt Kruse's library to create in that column a html element that is populated of a list of html elements that are computed dynamically by the js it self by picking a distinct and sole value of each record for that column.
When I wish to apply a filter to the table on the basis of certain column, I have just to choose the relative from the corresponding box and the table gets filtered accordingly, as I expect to. It works just hiding the records (the html rows) with not matching criteria in that specific column with a filter applied on it. Of course it is possible to use filters on more than one column at once if needed. It works pretty similarly to MS Excel.
The problem
When I apply a filter to a column the other columns filter drop-down combo boxes (the html elements that contain the compiled options for filtering other columns) continue to show all options instead of hiding those that are filtered in the table and are no more needed. So it becomes pretty tricky especially on complex tables to choose filtering criteria from other columns because the user has to understand by himself what are the criteria that aren't usable because the corresponding rows are already hidden by a filter already applied to another column.
One more thing: when I edit the content of one or more table cells, the filter of the relative column(s) doesn't update to match the editing made, but it seems to be to stay static.
Goal of this question
If I use a spreadsheet (as LibreOffice Calc, or MS Excel, or Google online spreadsheet, or else) when I filter a column other columns' filter drop down menu are filtered as well. If I remove a filter somewhere, other columns filters drop down are updated accordingly.
All this behavior is what I would like to implement into Matt Kruse's library. In this way it would be easier to filter by multiple columns because the boxes containing the filter criteria of the other columns will show just the filter criteria left by the all the previously applied filters.
What I have already tried
I tried to implement something to do that but it was so slow that I was too much ashamed of its execution time that I already deleted the whole algorithm I created.
For comparison using the Matt Kruse's library algorithm implies just few instants to compile all tables data into filter elements (on all tables as well). But the algorithm I've implemented needed more than 30-40 seconds for just one table. Way too inefficient.
Substantially I wrote few "for loops" that for each into each of the filtered table, compares the value of the option with each one of the corresponding column and if finds a mach keeps the option visible, else it hides that element into the . I attached that algorithm to the change event of each , so when I clicked and selected the the event was triggered and all the content of the table was updated. It worked as expected but, as I said, what I implemented was way slower.
So the question is:
How do I modify the Matt Kruse's js file to implement the feature I want keeping the highest possible performance?
(If Matt Kruse is reading this, feel free to pick up this idea and implement the new features needed above: I'm sure it would be greatly appreciated).
Thanks everybody in advance for the contribution.

React create Bootstrap grid of unknown size

I'm building an app in which I need to use React to render a Bootstrap grid. I'm a React newb so please bear with me.
Frontend will receive N objects that need to be displayed in Boostrap columns, each in his own column. The problem is, I don't know how large is N so I don't know how many rows do I need.
Any ideas how to approach this?
Should I have just one component? Or three (Container, Row, Column)? Or something else?
First of all, consider if you even need custom components for Container, Row and Column. You can just use a div with the appropriate css class, I don't see that much value in wrapping this into a custom component. If you do decide to use a custom component, you may want to look at react-bootstrap, they already implemented these.
As for the layout, I believe you can place as many columns as you want in a row in Bootstrap layout and they will wrap as necessary (if there's more than 12), so it might be easiest to just have one row and put all the columns inside it (see Bootstrap docs).
There are different ways to approach this problem depending on the type of content that you are trying to insert into the grid.
First off, as far as columns go, Bootstrap uses a 12 column grid system. This will make your life a bit easier because you can divide 12 by the number of elements in each row. If your html is set up correctly you can use:
var numOfElements = document.getElementById('objectsWrapper').children.length;
If you're using images you may want to set a strict max-height and max-width (percentages) to restrict the images generated from messing up the grid.
Next, when the column exceeds 12 elements, you'll want to start a new .row if necessary. Create a new div, append it to your current container and set it as the currentDiv you want to add your children to.This step is important because your code needs to know which 'objectsWrapper' it's querying for children.
Wash. Rinse. Repeat.
Hope this helps.

Freezing first column of JQgrid grouping table

I know that JQGrid doesn't support column freezing for grouping tables. But is there a customized JQGrid API to freeze the first column of JQGrid grouping table?
I don't see any simple way to implement freezing column together with grouping. When you call setFrozenColumns new "frozen body" <div> will be created over the body of the grid. jqGrid makes copy of the body of the grid in the div. The table with first frozen column will be copied from the main grid body in the table in the "frozen body" <div>. One can see for example + icon in the grouping header. In case of supporting of frozen columns one need to create the same icon on the "frozen body". The original icon will be not seen more till one calls destroyFrozenColumns method. The grouping header have grouping text which is over the whole columns of the grid. jqGrid uses colspan attribute in the cells of the header row. It could be not so simple to place in the "frozen body" so that text could be long and be over the whole rows. I suppose that the with on the header will be restricted to the width of the "frozen body".
I included the above comments just to describe that there are a lot of implementation details which need be solved if one would decide to implement freezing column together with grouping. I can repeat that I don't see any simple way to do this. One have to change many parts of the grouping module (grid.grouping.js) and probably the code of setFrozenColumns and destroyFrozenColumns to implement the requirement.

Extjs 4.2 Sortable grid with fixed position for one record

I have a simple grid with sorting on. I want to allow users to sort by any column, but at the same time I want one record to always display at last position (that record is recognized by ID). Is there a way to do this?
I'm using ExtJS 4.2.2.
I wouldn't keep a blank record for editing in the grid all the time. What I usually do is to provide the user a means to add record when he needs, let him to edit and save it.
You may have different requirements, anyway, you can see how this logic works here: Editable and Writable ExtJS Grid Example
This approach saves you from solving the sorting problem.

Dojo dgrid can have special rows listed on top

Can the dgrid have any functions to differentiate the rows? Data from server has two sets. One is the special set of rows that need to be displayed first on dgrid then the next set of data to be diaplayed with its own filter and sorting functions. Does dgrid support multiple data sets/store? Have to display the first data set all the time even while scrolling. I know that i can have two dgrids to accomplish this. Is it possible with one dgrid?
Thanks for the suggestions.
There isn't anything out of the box to help with something like this. I would suggest having two grids, one on top of the other, with the second having showHeader set to false. If you need to hijack the sort behavior of the header cells within the first grid, you can listen for the grid's dgrid-sort event, cancel it (with preventDefault), and programmatically perform operations on the second grid.

Categories

Resources