How to render an angularjs directive inside of a slickgrid cell - javascript

We have a large number of angularJS 1.5 directives (around 100) that we use throughout our applications. We also use slickgrid almost everywhere to display mass amounts of data. A project has recently come up where it would be ideal to be able to use our directives within slickgrid cells. So I've been trying to write a slickgrid editor to generate our directives when you go to edit one of the cells.
It seems as though angularJS doesn't pick up on the directive (because slickgrid doesnt operate within angular) and doesnt attach the element to its lifecycles. so basically the base element and its settings will appear in the HTML like this:
<div class="slick-cell l2 r2 active selected" title="">
<custom-directive></custom-directive>
</div>
but since angularJS doesn't process the directives there's no visible element in the view and none of the transcluded elements are created.
I've tried using $compile to sort of pre render the elements and then send them to slick grid, but that results in multilink errors which I'm not sure how to resolve.
I've also tried using a JS template with the hope that the template could be rendered and then used in a slickgrid editor later, but I haven't had success with that as of yet. I am still trying to make this approach work since I've seen other examples of using templates with slickgrid, but they aren't using angularJS so my situation doesn't quite fit to theirs.
To summarize I'm looking for suggestions on how I might approach this problem. I know slickgrid isn't technically supposed to be used in this fashion but there has to be a way to make this work. Reusing 100+ pieces of code to extend functionality here would be a very huge win.

Related

Copying bootstrap form elements from one theme to another

I'm building my first Yii2 app in bootstrap and I was looking at a few templates to base the UI in. The problem is that each one offers a few unique form elements that I like. Is it relatively easy to copy form elements from one theme to another?
For example, copying the Ui Elements > Tree View from http://wrapbootstrap.com/preview/WB0B30DGR into another template like http://wrapbootstrap.com/preview/WB0F0419C.
Thanks!
Depending on your experience in CSS and Javascript. I also customized on several occasions templates bootstrap changing some elements. First, it is whether you intend to do only the changes to the graphics and then only the changes to boostrap.css or if you want to supplement / modify the parts managed via javascrit. For graphics all template-type bootstrap behave the same way, then it needs to identify exactly which categories you care about and modify them with the catatteristiche want. For the part controlled by javascrit the situation is similar only the most delicate and complex.

reshuffling table columns with D3 or Angular

Hi fellow Javascripters,
I am using both Angular and D3 in my project (no jQuery, which I intend to keep this way). One thing that I want to support is to enable users to play with 'raw' tabular data. So, data from a CSV is loaded into my app and displayed in a plain old fashioned table (currently with Angulars ng-repeat). However, I now want to be able to animate that columns of the table get reshuffled. So, as a simple example, I would programmatically want to switch column 2 with column 4 and this transition must be D3-like. Furthermore, easily dragging whole columns to other positions should be possible.
Since I am not really experienced with working with jqLite inside Angular directives, my preference would go out to a solution based on D3. I can then see two possible solutions:
Render all of the data in a regular table using the D3 append functionality. Whenever column order changes, somehow reconstruct the table and create a smooth transition.
Simulate a table with div's and css (not looking forward to that though), to enable easy repositioning of data.
Since both solutions are far from trivial (I would say), I would really like to have some opinions. Do you see any other solutions for me? And if one of these two solutions seems right for you, how would you go about implementing them?
Thanks in advance!

KnockoutJS: How should I deal with heavy widget initialization code?

I'm currently trying to optimize our application that uses KnockoutJS for view binding and rendering. We discovered a huge bottleneck with a growing dataset size in the following scenario:
The dataset (observableArray) is displayed in an html table.
50 rows are displayed at the same time.
Each field in the row-model is an observable as the data is inline editable (input, select, ...)
Per row exist 8 selects that are initialized with the Select2 Widget (http://ivaynberg.github.io/select2) and a jQuery datepicker.
I already implemented these KnockoutJS performance tips, which I found on different sites:
The observable array is published with the full dataset (call of the observable) and not with multiple push() calls.
I'm using the template-binding in conjunction with the foreach option, as advised on multiple sites, and not both split up as separate binds.
Datepicker and Select2 are implemented as custom knockout bindingHandlers.
ko.applyBindings is invoked directly with the table-element as second parameter, so that not the whole DOM is bound by knockout.
But the main bottleneck in my opinion seems to be the initialization of the additional widgets. I measured the creation of a Select2 widget, which takes ~15ms. Of course that cummulates quickly with 50 rows and 8 columns. So, a single call on the observable array to load the full dataset takes up to 10 seconds! During this time, the Browser is under heavy load and becomes unresponsive, which is a no-go usability wise.
This leads up to my questions:
Has someone experienced a similar scenario and how was it handled?
Is there a better way to initialize third-party widgets with knockout?
Are there alternative ways (using KnockoutJS) to solve this problem?
Has someone experienced a similar scenario and how was it handled?
I have an interactive table on my page, which I display using the HandsOnTable plugin. The table has about 15 columns and I need to display up to 250 rows.
I bind it to an observableArray, and, at first, the observableArray contained only observables.
I was not satisfied with the speed of it in old versions of IE I am required to maintain (IE8/9, worked ok with IE11/recent Chrome), and made the decision to remove all observables inside the observableArray.
It is not really in the spirit of knockout and I am not so proud of this solution, but it does work much faster.
Handsontable lets you handle some events, in which I update the observableArray just like a regular array and then run the valueHasMutated function to notify the changes of the array.
Likewise, my custom binding handler watches changes on the whole observableArray and updates the table as needed.
I think the other difference with your solution is that Handsontable turns into edit mode only when needed, thus the plugins (like datepicker) load only then.
Is there a better way to initialize third-party widgets with knockout?
Maybe you can enter edit mode only when the line/cell is selected. You could then use an if binding to init and display your widgets only then.

multiple instances of SlickGrid using an angular directive?

I'm very new to AngularJS and so far I'm loving it.
I read that wrapping external libraries into directories is the kosher thing to do, and I understand why that makes sense.
In my efforts to create a 'slickgrid' directive, I found very little info on the web. This question over here provides an example of slickgrid as a directive: Slick Grid wrapped in directive (angular), some options not work (resize and drag&drop columns)
But is that the correct way of doing it? The way that person did it, every <div slickgrid> will initialize with the same settings and data.
In my app, I'll need many instances of slickgrid, and columns will differ from instance to instance, as well as the data, of course.
So how should I link a particular <div slickgrid> to the data that is supposed to display then?
thank you very much for your time
as SlickGrid has way too much options - there's no really big sense in writing a directive, that fully incapsulates it. You should better initiate different grids in different controllers. And maybe move column and formatter definitions to a separate service
So the code will be something like that:
angular.module('app').controller('grid1controller', function(){
...
$scope.grid = new Slick.Grid("#grid1", $scope.data, grid1columns, grid1options);
...
})

What's a good JavaScript grid with tabs?

I have 3 sets of tabular data I want to display with a JavaScript framework in ASP.NET MVC. I know I can embed a separate grid in a tab, but this seems inefficient especially when large datasets are involved since I imagine 3 separate grids would be created. I haven't found a JavaScript datagrid which emulates what a spreadsheet does with multiple tabs. This example from YUI might come close though:
http://developer.yahoo.com/yui/examples/datatable/dt_dynamicfilter_source.html
I'm a little familiar with jQuery, but would be willing to switch to any framework which makes this easy. I don't really need to edit the data. Any suggestions?
EDIT: I didn't mean this to be about jQuery. Maybe some details about my scenario would help, as suggested in one of the comments. I want to display tabular data from an ordering system containing thousands of records. I'd like 3 tabs:
All orders entered in the system which haven't been paid for yet.
All orders from a specific vendor.
All orders which have been paid for.
Since each category has thousands of rows, I only want to load data if the user starts paging.
I thought having 3 tabs with 3 separate grids (one within each tab) wouldn't be performant. I haven't actually tried though, so I'm probably guilty of prematurely optimizing. I'm looking for a grid with tab support built-in. I don't think there's one for jQuery. Perhaps ExtJS?
Since you tagged this with Ext JS, I'll mention that it's quite simple to render grids into tabs using Ext JS. It also supports deferred load/render, so that only the first tab/grid would load initially, then the others would be loaded on first access. Without knowing your specific requirements it's hard to comment further.
EDIT (based on edited question): Ext grids don't directly support tabbing, but they can be embedded within a TabPanel as I mentioned for the same effect. However, based on your description, it sounds more like a filtering scenario to me. I don't see the point in having the overhead of multiple grids when only one will ever be visible, and each one's purpose is to show a specific view (i.e. filter) of the same data. I would just have a single grid with a toolbar or some other method of providing your toggle between filters, and use Ext's built-in store filtering/querying to create your views on demand. The Ext grid supports paging out of the box (client or server, in your case it would be server for thousands of records). There is also a very popular plugin called LiveGrid that provides for virtual scroll-paging of large data sets.
I'm not necessarily advocating Ext over any other framework -- I just happen to be most familiar with it and I think it could solve your problem quite nicely. I would suggest trying it out for yourself to be sure.
jQuery Grid is kinda what people use a lot. I use it and it's pretty good.
jqGrid Link
I wouldn't draw a grid with three tabs. I'd use a single grid with a tab control and then load data via jQuery as required.
Or maybe have three PartialViews that you can load dynamically when you hit a tab.
You could also use dhtmlx grid.
You could use JS tab object to create tabs.
And use javascript grid framework to create grids and populate data into grids.

Categories

Resources